Pascal Wick

Pascal Wick

  • NA
  • 1
  • 0

How to access to a control encapsuled in a style

Feb 2 2009 11:44 AM

Hello I have a style with some control in my style.  The style do this : A user will select a territory and the disposition of the control will change.

The style work.  The style do what I want to do.

My problem is : I'm not able to access to a control txtNom1.  This textBox was encapsuled in my Style.

Xaml of my style :


<Window.Resources>

<Style x:Key="TerritoryStyle" TargetType="{x:Type jmb:View}">

<Setter x:Uid="monSetter" Property="Template">

<Setter.Value>

<ControlTemplate x:Uid="monTemplate" x:Name="monTemplate" TargetType="{x:Type jmb:View}">

<jmb:View x:Uid="monMainView" jmb:ViewItem.LabelPadding="5" jmb:ViewItem.LabelWidth="100"

jmb:ViewItem.LabelHorizontalContentAlignment="Right"

jmb:View.Territory="JMB_FR">

<Button Name="SwitchTerritory" Click="SwitchTerritory_Click">Switch</Button>

<jmb:View x:Uid="blocSaisieJMB_FR" Name="blocSaisieJMB_FR" jmb:ViewItem.LabelWidth="100" jmb:View.Territory="JMB_FR">

<TextBox Name="txtNom1" Text="{Binding Path=Nom}" jmb:ViewItem.LabelContent="Nom" Width="100"></TextBox> C'est a ce controle que je veux accéder en code behind.

<TextBox Name="txtPrenom1" Text="{Binding Path=Prenom}" jmb:ViewItem.LabelContent="Pr,nom" Width="100"></TextBox>

<TextBox Name="txt2emePrenom" Text="{Binding Path=Prenom2}" jmb:ViewItem.LabelContent="2Šme Pr,nom" Width="100"></TextBox>

<TextBox Name="txt3emePrenom" Text="{Binding Path=Prenom3}" jmb:ViewItem.LabelContent="3Šme Pr,nom" Width="100"></TextBox>

</jmb:View>

<jmb:View Name="blocSaisieJMB_ALL" jmb:View.Territory="JMB_ALL">

<jmb:View.ItemsPanel>

<ItemsPanelTemplate>

<StackPanel Orientation="Vertical"/>

</ItemsPanelTemplate>

</jmb:View.ItemsPanel>

<TextBox Name="txtNom2" Text="{Binding Path=Nom}" jmb:ViewItem.LabelContent="Nom :" Width="100"></TextBox>

<TextBox Name="txtPrenom2" Text="{Binding Path=Prenom}" Width="100" ></TextBox>

</jmb:View>

<jmb:View Name="blocSaisieJMB_ESP" jmb:View.Territory="JMB_ESP">

<jmb:View.ItemsPanel>

<ItemsPanelTemplate>

<StackPanel Orientation="Horizontal"/>

</ItemsPanelTemplate>

</jmb:View.ItemsPanel>

<TextBox Name="txtPrenom3" jmb:ViewItem.LabelContent="Pr,nom :" Text="{Binding Path=Prenom}" Width="100"></TextBox>

<TextBox Name="txtNom3" jmb:ViewItem.LabelContent="Nom :" Text="{Binding Path=Nom}" Width="100"></TextBox>

</jmb:View>

</jmb:View>

<ControlTemplate.Triggers>

<Trigger Property="jmb:View.Territory" Value="JMB_FR">

<Setter TargetName="blocSaisieJMB_FR" Property="Visibility" Value="Visible"/>

<Setter TargetName="blocSaisieJMB_ESP" Property="Visibility" Value="Collapsed"/>

<Setter TargetName="blocSaisieJMB_ALL" Property="Visibility" Value="Collapsed"/>

</Trigger>

<Trigger Property="jmb:View.Territory" Value="JMB_ALL">

<Setter TargetName="blocSaisieJMB_FR" Property="Visibility" Value="Collapsed"/>

<Setter TargetName="blocSaisieJMB_ESP" Property="Visibility" Value="Collapsed"/>

<Setter TargetName="blocSaisieJMB_ALL" Property="Visibility" Value="Visible"/>

</Trigger>

<Trigger Property="jmb:View.Territory" Value="JMB_ESP">

<Setter TargetName="blocSaisieJMB_FR" Property="Visibility" Value="Collapsed"/>

<Setter TargetName="blocSaisieJMB_ESP" Property="Visibility" Value="Visible"/>

<Setter TargetName="blocSaisieJMB_ALL" Property="Visibility" Value="Collapsed"/>

</Trigger>

</ControlTemplate.Triggers>

</ControlTemplate>

</Setter.Value>

</Setter>

</Style>

</Window.Resources>

Xaml where I call my Style :

      <jmb:View x:Name="mainView" Style="{StaticResource TerritoryStyle}" jmb:View.Territory="JMB_FR">


      </jmb:View>
      </Window>

Thanks


Answers (1)