我有一个没有标题栏的窗口。
<Window x:Class="WpfApplication1.PopupWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"
WindowStyle="None" ResizeMode="NoResize"
AllowsTransparency="True" Background="Transparent">
<Border Margin="10">
<Border.Effect>
<DropShadowEffect Color="Black"
Direction="270"
BlurRadius="10"
ShadowDepth="3" />
</Border.Effect>
<Grid Background="White">
<DockPanel>
<DockPanel Name="titleBar"
DockPanel.Dock="Top"
Height="32"
Background="LimeGreen">
<TextBlock Padding="8"
VerticalAlignment="Center"
Text="My Special Window"
Foreground="White"
FontWeight="999"
FontSize="16" />
</DockPanel>
<ContentControl Name="content" />
</DockPanel>
</Grid>
</Border>
</Window>
我有在 PopupWindow 中加载的恶意用户控件。
在 View 模型中,我用不同的内容显示此窗口。
SearchViewModel vm = new SearchViewModel();
SearchView view = new SearchView();
view.DataContext = vm;
PopupWindow window = new PopupWindow();
window.Owner = Application.Current.Windows.OfType<Window>().SingleOrDefault(x => x.IsActive);
window.Content = view;
window.ShowDialog();
为 PopupWindow 内容设置 Searchview,但我想为 ContentControl 的内容设置 searchview。我该怎么办?
最佳答案
不要在 Window 上设置 Content,而是直接在 ContentControl 上设置它:
window.content.Content = view;
关于c# - 将 ContentControl 内容与窗口内容绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25708823/