我有一個自定義設計的窗口如下所示。如何重用WPF中的自定義設計窗口?
以下是我的XAML設計,省略了簡單的樣式。
<Window x:Class="CustomWindowBase.MainWindow"
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:CustomWindowBase"
mc:Ignorable="d"
Title="CustomWindow" Height="600" Width="870" WindowStartupLocation="CenterScreen"
ResizeMode="NoResize" AllowsTransparency="True" WindowStyle="None" Background="Transparent">
<Border Style="{StaticResource MainWindowBorderStyle}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="35"/>
<RowDefinition Height="590*"/>
</Grid.RowDefinitions>
<Border Grid.Row="0" Style="{StaticResource TitleBarBorderStyle}">
<Grid>
<TextBlock Style="{StaticResource TitleStyle}" Text="Custom Window"/>
<Button x:Name="BtnClose" Style="{StaticResource CloseButtonStyle}"/>
</Grid>
</Border>
<Grid Grid.Row="1">
<!-- Different User Control Here -->
</Grid>
</Grid>
</Border>
</Window>
該窗口後面的代碼有兩個事件支持關閉/拖動操作。
我該如何重複使用這個shell到我的應用程序可能打開的每個其他窗口,有點像可以被繼承的基類?
如果可能的話,我不想在後面的代碼中做太多事情,例如實例化此窗口外殼的實例並將其內容與另一個用戶控件分配。
非常感謝您的幫助。
哇,那內容主持人是一些魔術!這正是我所尋找的,謝謝你的幫助,標記爲答案。 對於這些事件,我在我的App.xaml.cs中實現了Close和Drag,通過將發送者轉換爲其控件並執行Window.GetWindow()實例並調用Close和DragMove方法。 – IvanJazz