我用样式定义了一个窗口:
<Window x:Class="winBorderless"
x:Name="winBorderless"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Local="clr-namespace:WindowStyle"
Style="{StaticResource Window_Cartesia}"
WindowStartupLocation="CenterScreen"
BorderThickness="1"
BorderBrush="#FF9CAAC1"
Margin="5"
Title="[Document Title]">
以及在应用程序级字典中定义的样式:
<Style x:Key="Window_Cartesia" TargetType="{x:Type Window}">
<Setter Property="WindowStyle" Value="None"/>
<Setter Property="AllowsTransparency" Value="True"/>
<Setter Property="Background" Value="Transparent"/>
<EventSetter Event="Loaded" Handler="Loaded"/>
<EventSetter Event="PreviewKeyDown" Handler="Preview_KeyDown"/>
<EventSetter Event="MouseMove" Handler="FullScreen_MouseMove"/>
<Setter Property="Template">
在代码隐藏中,我引用了窗口实例集:
Win = DirectCast(sender, winBorderless)
这允许在事件设置器将引用传递给各个控件时访问窗口属性。但是,它不提供通过窗口引用访问样式中定义的控件,因为它们不存在。
那么,通过样式中定义的代码隐藏引用控件的最佳方法是什么?我不想重复这些树来找到它们,但你得做……