问题描述
在我的项目中,我有相同的标题 &所有窗口的页脚(我在这个项目中有超过 20 个 wpf 窗口),只有内容发生了变化.这是 WPF 项目.如果它是一个 asp.net,我在其中使用了母版页.
In my project I have same header & footer for all windows (I have more then 20 wpf windows in this project), Only Content has changed. This is WPF project. If its a asp.net I have used master page in that.
现在我复制粘贴标题 &页脚所有窗口.如果标题中需要任何小的更改,我必须在所有窗口标题中进行.有什么解决办法吗?
Now I copy paste header & footer all the windows. If any small changes needed in Header, I have force to do in all windows header. Is any solutions there?
推荐答案
我不是 100% 确定您所说的所有窗口"是什么意思,但一个好的方法是使用 header
和一个 footer
UserControls.
I'm not a 100% sure what do you mean by "all windows", but a good approach would be to have a header
and a footer
UserControls.
您可以随心所欲地设置它们,(文本、颜色等),然后,在你所有的窗口中,你可以有一个包含 3 个元素的网格,stackpanel,dockpanel,无论你想要什么,它都有 header
,然后是 content
,最后,您的页脚
.
You can set them whichever way you want, (text, colors, etc),and then, in all your windows you could have a grid with 3 elements, stackpanel, dockpanel, whatever you want, which will have the header
, then your content
, and last, your footer
.
根据评论:而不是拥有这个:
As per comment: Instead of having this:
<Window ...>
<StackPanel>
<Label>one</Label>
<Label>two </Label>
<Label>three</Label>
</StackPanel>
</Window>
你可以有一个 UserControls(假设叫做 HeaderControl
),然后你需要做的就是
You can have a UserControls (lets say called HeaderControl
), and then all you need to do is
- 添加命名空间以便您可以使用它.
- 像添加任何其他控件一样添加它.
- 享受可重用性.
步骤说明:
将它与其余的
xmlns....
定义一起添加到您的 windown 中:xmlns:controls="clr-namespace:WpfApplication1"
Add this to your windown with the rest of the
xmlns....
definitions:xmlns:controls="clr-namespace:WpfApplication1"
将第一个控件从标签更改为我们的资源:
而不是 <Label>one</Label>
写:
Changing the first control from label to our resource:
Instead of <Label>one</Label>
write: <controls:HeaderControl />
这篇关于相同的标题 &所有 WPF 窗口中的页脚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!