何时在WPF中使用用户控件

编程入门 行业动态 更新时间:2024-10-25 10:25:03
本文介绍了何时在WPF中使用用户控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有一个看法,过滤一个DataGrid,我想使用相同的集合的完全相同的过滤(除了列将是不同的)在不同的视图。

当然,我不想在这个新视图中复制XAML,所以当用户控件是正确的事情吗?

我唯一的问题是,新的DataGrid将被放置在新视图的下面,这样可能吗?而且正如我上面所说的那样,这些列在过滤中可能会有所不同,所以在用户控制中再次有可能出现这种情况?

感谢

解决方案

想要创建一个UserControl一种新的UI控件,或者导出一个现有的控件,并增强其功能。

你需要的是一个样式,你想要设置certian属性您对证书价值的控制:

< Style TargetType =Button> < Setter Property =BackgroundValue =Red/> < Setter Property =Template> < Setter.Value> < ControlTemplate TargetType =Button> < Grid> < Rectangle Fill ={TemplateBinding Background/> < ContentPresenter /> < / Grid> < / ControlTemplate> < /Setter.Value> < / Setter> < / Style>

I have a view that Filters a DataGrid and I want to use the the exact same filtering with the same collection (apart from the columns will be different) in a different view.

Of course I dont want to duplicate the XAML in this new view, so is this when a user control would be the correct thing to do?

My only problem is that a new DataGrid will be put underneath in the new view so would this be possible? And as I said above, the columns also may be different in the filtering, so again, possible within a user control?

Thanks

解决方案

A UserControl should be used when wanting to create a new kind of control for your UI, or derive an existing control and enhance its capabilities.

What you need sounds like a Style, where you want to set certian properties of your control to certian values:

<Style TargetType="Button"> <Setter Property="Background" Value="Red"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Button"> <Grid> <Rectangle Fill="{TemplateBinding Background"/> <ContentPresenter/> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style>

更多推荐

何时在WPF中使用用户控件

本文发布于:2023-11-03 06:33:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1554464.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控件   用户   WPF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!