C# wpf controltemplate应用于窗口,以及如何添加控件
我定义了一个用于windows的controltemplate,windows的视图基本上与windows相同。C# wpf controltemplate应用于窗口,以及如何添加控件,c#,wpf,controltemplate,C#,Wpf,Controltemplate,我定义了一个用于windows的controltemplate,windows的视图基本上与windows相同。 之后,我应该在不同的窗口中添加不同的控件。我不知道如何在controltemplate中添加元素的宿主来保存控件的不同部分,就像下面的图片一样 还有一件事,如何访问控件以及如何在不同窗口的controltemplate中设置按钮的操作?应该使用windowBase类来实现这一点吗 首先,屏幕图片 和控件模板文件 。/images/others/popup\u btn\u red
之后,我应该在不同的窗口中添加不同的控件。我不知道如何在controltemplate中添加元素的宿主来保存控件的不同部分,就像下面的图片一样
还有一件事,如何访问控件以及如何在不同窗口的controltemplate中设置按钮的操作?应该使用windowBase类来实现这一点吗 首先,屏幕图片 和控件模板文件
。/images/others/popup\u btn\u reduction\u normal.png
../images/others/popup\u btn\u reduce\u mouseover.png
../images/others/popup\u btn\u reduction\u selected.png
还有window.xaml
我自己做的。
只需使用下面的代码来托管新控件
<AdornerDecorator>
<contentpresenter/>
</AdornerDecorator>
并创建一个windowBase作为新窗口的父类
<Window x:Class="WpfApp1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1"
xmlns:uctrls="clr-namespace:WpfApp1.Uctrls"
mc:Ignorable="d"
Style="{StaticResource WindowBaseStyle}"
Title="Window1 -- title" Height="300" Width="500">
<Grid>
<Label x:Name="lblTitle" Content="title"></Label>
<Button x:Name="BtnTest" Content="Get TextBox1" Click="BtnTestClick"></Button>
<uctrls:UserControlBase>
<Grid>
<Button Content="what "></Button>
</Grid>
</uctrls:UserControlBase>
</Grid>
<AdornerDecorator>
<contentpresenter/>
</AdornerDecorator>