美文网首页
WPF中如何在XAML中将窗口的DataContext指定为th

WPF中如何在XAML中将窗口的DataContext指定为th

作者: 达哥傻乐 | 来源:发表于2021-09-07 14:35 被阅读0次

需要在WPF中通过XAML将窗口的DataContext指定为this很简单,如下所示:

<Window x:Class="MySystem.WindowProjectOptions"
        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:MySystem"
        mc:Ignorable="d"
        Title="Project Options" Height="450" Width="400" ShowInTaskbar="False" SizeToContent="Height"  WindowStartupLocation="CenterOwner" WindowStyle="ToolWindow" 
        x:Name="_this"
        DataContext="{Binding ElementName=_this}"
        >
    <Grid>
    </Grid>
</Window>

关键即在倒数第5和6行:

        x:Name="_this"
        DataContext="{Binding ElementName=_this}"

达叔傻乐(darwin.zuo@163.com)

相关文章

网友评论

      本文标题:WPF中如何在XAML中将窗口的DataContext指定为th

      本文链接:https://www.haomeiwen.com/subject/ezxpwltx.html