窗口可见性不适用

时间:2017-07-13 03:03:47

标签: wpf windows xaml

以下代码不会使我运行的窗口不可见。我错过了什么?最初,我的目标是将窗口的可见性绑定到模型视图的WindowVisibility布尔属性,但是当它不起作用时,我删除了条件触发并且只分配了一个样式,将其设置为折叠但是它仍然没有工作。

<Window x:Class="WindowWalker.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Width="1000" MinHeight="10" Height="85" ResizeMode="NoResize" Topmost="True" WindowStyle="None" Loaded="Window_Loaded" WindowStartupLocation="CenterScreen" SizeToContent="Height">
    <Window.Style>
        <Style TargetType="{x:Type Window}">
            <Setter Property="Visibility" Value="Collapsed"/>
            <!--<Style.Triggers>
                <DataTrigger Binding="{Binding WindowVisibility}" Value="True">
                    <Setter Property="Visibility" Value="Collapsed"/>
                </DataTrigger>
            </Style.Triggers>-->
        </Style>
    </Window.Style>
    <Window.Resources>
        <ResourceDictionary>
            <VisualBrush x:Key="SettingsBrush" Visual="{StaticResource appbar_settings}"/>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Resources/Icons.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>
    <Grid>
        <StackPanel Orientation="Vertical">
            <TextBox Text="{Binding SearchText, UpdateSourceTrigger=PropertyChanged}" FontSize="40" Margin="10" KeyUp="SearchBoxKeyUp"/>
            <ListBox x:Name="results" ItemsSource="{Binding Results}" SelectedItem="{Binding SelectedWindowResult}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding ResultWindow.Title}"></TextBlock>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </StackPanel>
    </Grid>
</Window>

0 个答案:

没有答案