开发者

Using custom control's alias in XAML

In a WPF (Silverlight) UserControl I have lots of custom control instances:

<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/present开发者_如何学Goation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:My="clr-namespace:MyProject;assembly=MyAssembly" Name="uc1" >
...
<Grid x:Name="grid1">   
...   
  <My:CustControl x:Name="name1" />   
  <My:CustControl x:Name="name2" />   
  <My:CustControl x:Name="name3" />   
... 
</Grid> 

In MyProject I have not only the CustControl implemented, but also the CustControl1, the CustControl2, the CustControl3 and the like. Sometimes, I have to use another custom control type in the UserControl. Can I have only one place for changing custom control's name instead of changing it in all the numerous references in the XAML?

In other words, can I use an alias for those multiple custom control references inside my XAML and one place where I define the real CustomControl class' name for that alias?

Or maybe some other approach for solving this problem?


You could write a simple empty wrapper class, which would inherit the control you currently use. Then in XAML you would use this wrapper instead of the specific CustControl. At any time, you could change the base class for the wrapper at one single place.

But I must say: this design stinks. Are you sure you couldn't solve this issue with global styles/templates for one CustControl class?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜