x:name of controls in ApplicationViewStates - xaml

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

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.

Related

Reference string resource in Windows Phone 8.1 XAML

I am unclear how do I reference a control text property using string resources in Windows Phone 8.1?
For instance I have:
<HubSection x:Name="MySection" HeaderTemplate="{StaticResource MyHeaderTemplate}" Header="{StaticResource MyText}">
and
<AppBarButton Name="MyAppBar" Label="{StaticResource MyText}" ...>
and
They both reference MyText which I want to load from resource .resx file.
To Refer Any control Property from resources in the XAML, create a x:Uid for that control say for a TextBlock, I made a control like :
<TextBlock x:Uid="Header" Text="from Resx" Style="{ThemeResource TitleTextBlockStyle}"/>
And in the Resources.resx define a new Resource with name Header.Text and Value as desired say, My Header Text. See the screenshot below :

Order of bindings in Windows Phone 8

I am facing this issue regarding data binding and binding in a converter while developing a Windows Phone 8 app.
I am trying to send the button to a converter so I can access all of its properties using the following code
<Button Content="{Binding OwnBoard, Mode=OneWay}" Grid.Row="0" Background="{Binding RelativeSource={RelativeSource Mode=Self}, Converter={StaticResource BoardToBackConv}}" />
When I hit the break point in the converter I have the button as the binding object, but the Content property of the control is Null. I need to access the object stored in the Content property.
As far as I know, because of the order of the bindings, the Content property should already contain a value.
Any idea how to make this work?
I have managed to understand why what I want to do is not going to work.
Keeping it short, the converter is executed during the InitializeComponent() call, and at that time the other binding was not done, because there is not DataContext for the view yet.

How to use x:Uid in windows phone 8?

We can use x:Uid in windows-8 as
Where in .resw I have define
mainTitle.Text = "Your Name"
In this way TextBlock's text becomes Your Name.
How can I achieve the same in windows phone 8?
When I put mainTitle.Text in .resx it gives error.
You have to use binding in Windows Phone 8.
The most simple way to see this in action is to create a new project and take a look at MainPage.xaml. The binding is demonstrated in the following comment
For example:
Text="{Binding Path=LocalizedResources.ApplicationTitle, Source={StaticResource LocalizedStrings}}"
To localize some text, you bind the LocalizedStrings class (created with the project) which wraps your static Resource file.
<TextBlock Text="{Binding Path=LocalizedResources.ApplicationTitle, Source={StaticResource LocalizedStrings}}" />
The LocalizedStrings resource is already there in your App.xaml
<local:LocalizedStrings x:Key="LocalizedStrings"/>
You can use binding here
<TextBlock Text="{Binding Path=LocalizedResources.ApplicationTitle, Source={StaticResource LocalizedStrings}}"/>
For more about localization read How to build a localized app for Windows Phone
And to know about x:Uid read x:Uid Directive
Binding is one solution but simply you can do the following.
If you have the following AppBarButton
<AppBarButton
Name="AppBarButtonMore"
x:Uid="appbar_more_title"
Click="AppBarButtonMore_Click"/>
add the string file with the key appbar_more_title.Label to your resources and your button will take that string as label property.This is also valid for any UI controls.

How to reuse XAML code blocks without binding?

I have this XAML code block:
<StackPanel Orientation="Horizontal">
<TextBlock Text="Hello " />
<TextBlock Text="World" />
</StackPanel>
I would like to define this block (for example in /Common/CustomStyles.xaml) to include it on different XAML pages. How does it work?
I do not need a DataTemplate or something similar because the text is static.
You could put it in a user control and re-use it that way. If it's just the text you are interested in then you could use a resource file - this would update the textbox on any screen as long as it had the right uid.

Silverlight - displaying graphical resources within a button

Has anyone solved this: displaying graphical resources within a button
create a resource, for instance a rectangle
<UserControl.Resources>
<Rectangle x:Key="myRectangle" Fill="Red" Height="100" Width="100"/>
</UserControl.Resources>
then set the content of the button to the resource
<Button Content="{StaticResource myRectangle}"/>
when you build inside blend 4 RC you get the error "Value does not fall within the expected range."
Visual studio does not show this error.
When you run the site the button doesn't show any content.
This technique works in WPF without problems.
Anyone got any ideas?
This can be done by directly setting the shape as the button's content. For eg:
<Button Height="120" Width="120">
<Rectangle Fill="Red" Height="100" Width="100"/>
</Button>
FrameworkElement.Resources are generally used for storing nonvisual elements, brushes, etc. For your case (I think) you'll need to store your xaml as a data template, again not sure if this works with Buttons, it is used for things like ListBoxes. See here:
resources description on msdn. The link further contains pointers to information for Data Templates etc.