I've been following this tutorial Using String resources (xaml) to set up string resources, in a Windows Universal project. But even though I've set the Uid of the text block to the string resource name, the string contents aren't displayed in the text block during testing the app.
Does anyone know where I might be missing a step in setting up the string resource
as the text block text value?
This is the xaml definition for the text block, showing the Uid set to the same name as the name of the string in resources "About":
<TextBlock x:Uid="About"
Grid.Row="1"
Grid.RowSpan="2"
Width="400"
Height="300"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Text=""
TextWrapping="Wrap" />
This is the res file itself:
And this is the structure of the source tree:
Resources files when accessed using UID are usually of the type Controlname.Property for which you want to bind.
So it should be About.Text not About tested And Working
Related
I'm trying to make an interface with multiple language options on a WPF screen. I'm writing the name of the text block I want to add to my Resources file and my code, but on the xaml screen "The member "Manuals" is not recognized or is not accessible." I get an error. I am getting this error in all the buttons and texts I try to add. Can you help me understand why? There is my xaml code line and resources designer cs project code line. Thanks in advance.
public static string _Manual
{
get
{
return ResourceManager.GetString("Manuals", resourceCulture);
}
}
<TextBlock Name="ttbManuals" Grid.Row="8" Text="{x:Static resx:Resources._Manual}" HorizontalAlignment="Left" Margin="0,0,0,-20" VerticalAlignment="Top" Height="39" Width="580" Style="{DynamicResource CncTextBlock}" Background="{DynamicResource BackgroundBrush1}" Padding="10,5,0,0"/>
The Resources class is by default created as internal. For use in XAML it needs however to be public.
To fix it, select the resx file in solution explorer and in the properties, change ResXFileCodeGenerator to PublicResXFileCodeGenerator.
See also here: Visual Studio - Resx File default 'internal' to 'public'
I tried to use Resources files (.resw) for multi-language.
On the project's root folder, I now have :
.\Strings\fr-FR\Resources.resw
&
.\Strings\en-US\Resources.resw
On both files, I just have
NAME VALUE
Welcome Welcome !
and So, I tried to call this reference into a XAML file, but the TextBlock stays empty
<TextBlock Text="" x:Uid="Welcome" MinWidth="200" Height="20" />
If the Text is set manualy, it appears, but here, nothing appears.
Any ideas ?
the name in the string of your resw-file should be Welcome.Text, because you are setting the text property of the textblock.
Then:
<TextBlock x:Uid="Welcome" MinWidth="200" Height="20" />
I currently have a large license file embedded in my program that I'd like to bind a RichTextBox to. I've tried multiple methods but found no good way to do this without including something in the code-behind. I'd prefer to bind the document in the XAML itself. As an analogue, I currently have an image bound like so:
<Image Height="25" HorizontalAlignment="Left" Margin="12,12,0,0" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="23" Source="Resources\68PVb9k.png" />
Is there any way to achieve this with a RichTextBox document? If I attempt to bind the document directly I get an error:
"A 'Binding' cannot be set on the 'Document' property of type 'RichTextBox'. A 'Binding' can only be set on a DependencyProperty of a DependencyObject."
So something like:
<RichTextBox Name="richTextBox1" Document="{Binding Path=Resources\InternalLicense.txt}" IsEnabled="False"/>
Won't work. (I realize the obvious formatting issues there. It's just an example)
TextBox IsReadOnly = true
TextBoxBase.IsReadOnly Property
I want to give the user the option to change language so I created two resource files, one for Portuguese and another for English (US).
For the name field I'm giving it names like String1, String2, String3, etc... And in the value field I'm writing the names of my buttons, for PT and EN.
I'm using the following code in my xaml file to bind the strings to my buttons:
<Button Content="{Binding Resources.String5, Source={StaticResource Strings}}" BorderThickness="0" VerticalContentAlignment="Bottom" FontSize="29.333">
<Button.Background>
<ImageBrush Stretch="Uniform" ImageSource="images/Warning-icon.png"/>
</Button.Background>
</Button>
The problem is in String5. It doesn't show up. It works great for String1 to String4, but after that it doesn't show anymore strings.
Image: http://snag.gy/PLcET.jpg
Is there any string limit for a resource file?
Solved. Besides the PT and EN resource files I also have a String resource file. That is the original file that I created. PT and EN files are a copy of it with the respective culture code (pt-PT and en-US). I had to add String5 in that file as well.
I have a little question.
I have a data template like that :
<phone:PhoneApplicationPage.Resources>
<DataTemplate x:Key="DangersItemTemplate">
<Grid Height="102" Width="447" Tap="Grid_Tap">
<Image Name="image" Source="{Binding Image}" HorizontalAlignment="Left" Width="90" />
<TextBlock Name="text" Text="{Binding Nom}" TextWrapping="Wrap" Margin="102,16,16,22"/>
</Grid>
</DataTemplate>
</phone:PhoneApplicationPage.Resources>
I want to use the Textlock control in the CSharp code to pass the Text property to the second xaml page, but I can't find the name of the control, it's inaccessible.
Any idea ?
Your binding the Text of the TextBlock so you must have the value in your datacontext. I'd add this value to the Querystirng and navigate to the page.
var text = ((Whatever) DataContext).Nom;
string page2Uri = string.Foramt("/PAge2.xaml?Nom={0}", text);
NavigationService.Navigate(new Uri(page2Uri, UriKind.Relative));
And then to get the data out of the querystring you can use the OnNavigatedTo method in your page, and then inspect this.NavigationContext.QueryString["nom"]
Or have a look into something like the MVVM pattern.
I just use VB.Net but I am sure you can convert.
Just use any shared variable in the application.
Here you can see it in an SourceCode example:
http://www.activevb.de/rubriken/kolumne/kol_30/res/nachtscanner.zip
Just use Public Shared MyText As String
in Application Class. This vairable you can access anywhere.
You can also use INotifyPropertyChanged for that shared property to bind.
Alternatively you can use Navigation Query. Read more here:
How can I pass query string variables with NavigationService.Navigate?