What is the Difference Between x:Key, x:Name, and x:UID in a DataTemplate in WPF?

前端 未结 2 689
后悔当初
后悔当初 2021-02-03 21:16

I am trying to create dynamic tabs in WPF, and I\'m trying to write a content template that will only apply to some tab items. I want to be able to create an identifier for the

2条回答
  •  盖世英雄少女心
    2021-02-03 21:33

    If you want to apply the template to all the tabs in your page, you can use x:Type, but if you want to apply it to few tabs and not to all the tabs you can use x:Key.

    Generally you will use x:Key when you want to use it as StaticResource in your xaml file. You will provide x:Name to a control or template when you want to refer it in your code-behind. I have never used X:Uid, but this is what MSDN says,

    Use x:Uid to identify an object element in your XAML. Typically this object element is an instance of a control class or other element that is displayed in a UI. The relationship between the string you use in x:Uid and the strings you use in a resources file is that the resource file strings are the x:Uid followed by a dot (.) and then by the name of a specific property of the element that's being localized.

提交回复
热议问题