Not able to bind to Uid or Name property in XAML
Join the DZone community and get the full member experience.
Join For Free<Window x:Class="WpfApplication2.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication2"
Title="Window1"
Height="300"
Width="300">
<Grid>
<Grid.CommandBindings>
<CommandBinding Command="local:AppCommands.Find"
CanExecute="CanFind"
Executed="CommandBinding_OnExecuted"/>
</Grid.CommandBindings>
<StackPanel>
<TextBox Name="textBox1"/>
<Button Command="local:AppCommands.Find"
Name="{x:Static local:Window1.MyControlName}"/>
</StackPanel>
</Grid>
</Window>
…
namespace WpfApplication2
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public static readonly string MyControlName = "name";
Gives this compilation error
c:\Dev\.NET\WpfApplication2\WpfApplication2\Window1.xaml(17,21): error MC3079: MarkupExtensions are not allowed for Uid or Name property values, so '{x:Static local:Window1.MyControlName}' is not valid. Line 17 Position 21.
Published at DZone with permission of Merrick Chaffer, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments