0
votes

I am working in windows store apps and I need help.. I am trying to adapt my app for the differents visual state (FullScreenLandscape, FullScreenPortrait, Snapped, etc) and I need to reuse the controls for each visual state..

I create a grid for each visual state for example

        <Grid x:Name="PortraitView" Visibility="Collapsed">

        </Grid>

        <Grid x:Name="FillView" Visibility="Visible">

        </Grid>

        <Grid x:Name="SnapView" Visibility="Collapsed">

        </Grid>

but my problem is that I can not repeat the x:name of the controls that I set in the Grid= PortraitView..

how can I resolve it?

thanks

1
Why would you need to have same names of different elements? - Filip Skakun
@FilipSkakun no, for example in the FillView i have a button with x:name="btnTest" and i need this button for the SnapView and PortraitView (i need to adapt the button for the application state).. how i do this? - Mauro Petrini
You have multiple buttons that use the same Click event handler or same Command binding. - Filip Skakun
@FilipSkakun it is true, but if I have a textbox ? example: I need to create a new user (some textboxs with their values), in this case I need to create four methods? one per ApplicationView ?? because if you say to me that I change de x:name of the controls.. I do not know if you understand me.. - Mauro Petrini
Oh, the easiest way is to use the binding markup extension. You create a simple view model class with properties for the different fields in your view, then set the DataContext of your page to an instance of the view model and in your view (page) set things like <TextBox Text="{Binding FieldText, Mode=TwoWay}"/> assuming your view model has a property called FieldText. Make sure the view model implements the INotifyPropertyChanged and raises PropertyChanged event in the property setter. - Filip Skakun

1 Answers

1
votes

From MSDN

The most common usage of this property is to specify a XAML element name as an attribute in markup. This property essentially provides a WPF framework-level convenience property to set the XAML x:Name Directive.

Names must be unique within a namescope.

For more information, see XAML Namescopes.