我想在wpf中的app.xaml窗口内容模板中放一个关闭按钮

时间:2015-09-02 12:02:41

标签: wpf vb.net xaml

我已经创建了目标类型窗口的自定义模板现在我希望每当我声明模板时按钮自动作为右上角的关闭按钮到达以关闭窗口但是在app.xaml的代码我不知道按钮点击执行表单关闭处理程序。

  <Application x:Class="Application"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
    <Style x:Key="MyWindowStyle" TargetType="Window">
        <Setter Property="WindowStyle" Value="None"></Setter>
        <Setter Property="Background" Value="#FFCDFF"></Setter>
        <Setter Property="WindowState"  Value="Maximized"></Setter>
    </Style>

    <ControlTemplate TargetType="Window" x:Key="WindowTemplate">
        <AdornerDecorator>
            <Grid Background="{TemplateBinding Background}">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Control x:Name="FocusCatcher"></Control>
                <TextBlock Text="Menu Section" HorizontalAlignment="Center"/>
                <Button Content="X" FontFamily="Tahoma" Width="25" HorizontalAlignment="Right"></Button>
                <ContentPresenter Grid.Row="1" />
                <StatusBar Height="23" VerticalAlignment="Bottom" Grid.Row="2">
                    <TextBlock Text="Current Editing Mode" />
                </StatusBar>
            </Grid>
        </AdornerDecorator>
    </ControlTemplate>
</Application.Resources>

并在Mainwindow.xaml

  <Window x:Class="MainWindow" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" Style="{StaticResource MyWindowStyle}" Template="{StaticResource WindowTemplate}">
<Grid>

</Grid>

表单看起来像这样:[1]

1 个答案:

答案 0 :(得分:1)

如果我说对了你想按下按钮点击窗口关闭? 然后为你的按钮添加一些额外的xaml:

ENV MY_DB_URL %MY_DB_URL%

并在代码中实现

url(r'^articles/get/(?P<article_id>\d+)/comments/(?P<comments_page_number>\d+)/$', 'article.views.this_article'),

关闭它。