开发者

Setting x:Name on the UserControl tag inside a UserControl sometimes crashes the application

I've created a UserControl named Marked. The code for the control is :

<UserControl .... x:Name="marker">
   <StackPanel Orientation="Vertical" x:Name="LayoutRoot">

      <Image Source="{Binding Path=MarkSource, ElementName = marker}" Visiblity="{Binding Path=IsMarked}"/>  

   </StackPanel>
</UserControl>

In the code behind I've set two dependency properties: MarkSource and IsMarked.

When I use the control I do something like this:

<my:Marker MarkSour开发者_如何学JAVAce="mark.jpg" IsMarked = {Binding Path=Person.IsActive}/>

The problem is: 1. The custom control works. 2. Sometimes when I'm starting the application I receive the following error: Xaml tree error the name marker already exits.

when I restart the application it works correctly.

I've tried removing the x: from the x:Name="marker" to Name="marker" but the binding on the image doesn't work. I've tried setting up binding in the code behind, it also doesn't work.

What is the problem with the x:Name?


Try to give x:Name to your Image control.
Remove x:Name from your UserControl.
In code behind set DataContext of your image to this.
Remove ElementName = marker in your binding.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜