2016-06-27 2 views
0

スタックパネル(コントロールテンプレート)内のボタンにアクセスするには?私はそれらのボタンを単一のボタンオブジェクトとして作らなければならないことを意味します。Wpfのアクセス制御テンプレートコントロール?

<Window.Resources> 
    <ControlTemplate TargetType="Button" x:Key="temp" x:Name="hotel"> 
     <StackPanel x:Name="service"> 

       <Button Content="1" Width="30" Height="30" Name="tempbtn1"/> 
       <Button Content="2" Width="30" Height="30" Name="tempbtn2"/> 
       <Button Content="3" Width="30" Height="30" Name="tempbtn3"/> 
       <Button Content="4" Width="30" Height="30" Name="tempbtn4"/> 
      </StackPanel> 

    </ControlTemplate>  
</Window.Resources> 

<Grid> 
    <TextBox x:Name="txttype" TextWrapping="Wrap" Text="Room Type" Width="120" Height="30" Margin="10 0 0 0"/> 
    <Button x:Name="button" Content="Submit" HorizontalAlignment="Left" Margin="9,0,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click"/> 

    <StackPanel Orientation="Horizontal" x:Name="Deluxe"> 
     <Button x:Name="btn1" Content="1" Width="60" Height="60" Template="{StaticResource temp}"/> 
     <Button Margin="10 0 0 0" Content="2" x:Name="btn2" Width="60" Height="60" Template="{StaticResource temp}"/> 
    </StackPanel> 
</Grid> 
+4

あなたが達成するために何をしようとしていますか? 1つのボタンを4つのボタンに分割することは、私には意味をなさない。あなた自身を説明してください – lokusking

+0

もし私がテキストボックスに1を与えたら、ボタンのコントロールテンプレート(btn1という名前)の最初のボタンはその背景色を変更する必要があります。 – Divagar

答えて

0

私はあなたの正確な要件を理解していません。しかし、私は次の情報があなたに役立つことを願っています。

コントロールテンプレート内で宣言された要素を取得するための一般的な構文は次のとおりです。

あなたのサンプルで
var template = controlName.Template; 
var myControl = (typeofthecontrol)template.FindName("MyControlName",controlName); 

var template = btn1.Template; 
var myControl = (Button)template.FindName("tempbtn1", MyList); 
関連する問題