Over a million developers have joined DZone.

Not able to bind to Uid or Name property in XAML

·
Even though x:Name is a dependency property for a WPF framework element, you cannot the name of the control to a static resource in the code behind file.

<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.




Topics:

Published at DZone with permission of Merrick Chaffer, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}