What does x:Static mean [duplicate] - wpf

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
What does “{x:Static}” mean in XAML?
In a xaml file there is:
Command="{x:Static src:CustomCommands.Create}"
What does the x:Static mean? If I remove it then it throws an error when loading the xaml saying it "Cannot create unknown type CustomCommands.Create"

http://msdn.microsoft.com/en-us/library/ms742135.aspx
The link above from MSDN mentions:
References any static by-value code entity that is defined in a Common
Language Specification (CLS)–compliant way. The static property that
is referenced can be used to provide the value of a property in XAML.

Related

XAML: how to access items from resources.resx [duplicate]

This question already has answers here:
How to get a Uri of the image stored in the resources
(2 answers)
Assign BitmapImage from Resources.resx to Image.Source?
(1 answer)
Not able to reference Image source with relative path in xaml
(3 answers)
Closed 3 years ago.
I'm learing WPF and XAML. I'm trying to show an image loaded from resources.resx.
For this, I've added an existing image to resources.resx. The identifier of the image is GoogleLogo. If I open Resources.ResX is can see that the image indeed is present in the resource file.
Now I want a window that shows this image in a Grid. The XAML is like:
<Window x:Class="WpfDemo.MainWindow"
xmlns=...
Title="Show Google Logo" Height="160" Width="800">
<Grid>
<Image Source="???"/>
</Grid>
</Window>
How to refer to the Source in resources.ResX? What to type instead of ???

Which DataContext is used for my UserControl in the DataTemplate of a DataGrid? [duplicate]

This question already has answers here:
Issue with DependencyProperty binding
(3 answers)
How to correctly bind to a dependency property of a usercontrol in a MVVM framework
(4 answers)
Closed 5 years ago.
I have a datagrid, which is filled by a datatable. Each entry in the table is an object of a custom type. For each cell I want to use an usercontrol to show the content. I use XamlReader to create the usercontrol in code behind.
I learned that the DataContext of the DataTemplate for the columns CellTemplate is a DataGridRow and I could access an element with the following code:
$#"<DataTemplate
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"">
<TextBox Text=""{{Binding [{count}].Amount}}"" />
</DataTemplate>"
When I try the same with my usercontrol it fails:
$#"<DataTemplate
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"">
<local:MyControl
MyProperty=""{{Binding [{count}]}}""
xmlns:local=""...
with the error:
BindingExpression path error: '[]' property not found on 'object'
Is the DataContext different when I use custom control? I don't get it...

ValueTuple With WPF Binding [duplicate]

This question already has answers here:
Is it possible to bind to a ValueTuple field in WPF with C#7
(3 answers)
Closed 4 years ago.
why binding to ValueTuple property members (like Item1, Item2 ect) dont work?
<TextBlock x:Name="txtTest" Text="{Binding Item1}" />
the code:
txtTest.DataContext = ("Item A", "Another Item..");
output window:
BindingExpression path error: 'Item1' property not found on 'object' ''ValueTuple`2'
However in Tuple It always worked.
As stated in the documentation, Item1 and Item2 of a ValueTuple are fields rather than properties and you can only bind to public properties in WPF.
So if you want to be able to bind to a tuple, you should use the Tuple class.

Use StringFormat for special output in XAML-Binding [duplicate]

This question already has answers here:
StringFormat is ignored
(3 answers)
Closed 6 years ago.
I have an integer value named Id and want a Label in Xaml to display the following:
(ID: 160)
I tried the following:
<Label Content="{Binding Id, StringFormat='(ID: {0:0})'} />
but it doesn't work - it just displays the value of Id:
160
How can I get this working without using a special ValueConverter class?
You have to use ContentStringFormat for content controls instead of the binding's StringFormat, has been asked various times before, will have to look for that.

Why does WPF have x:Name and Name XAML? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
In WPF, what are the differences between the x:Name and Name attributes?
Why does WPF have x:Name and Name XAML? What's the deal with x:Name?
Long story short: x:Name is an attached property and can thus be set on everything. Name is not an attached property and thus is only available on things that expose a Name property. WPF aliases Name to x:Name so you are safe to always use x:Name and this is what is recommended as you can use it everywhere.

Resources