将Window1图标绑定到MainWindow图标

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将Window1图标绑定到MainWindow图标相关的知识,希望对你有一定的参考价值。

我尝试了下面的代码,但它不起作用。有什么建议?

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="Window1" x:Name="Window1" Title="Window1" 
    Height="300" Width="300"
    Icon="{Binding ElementName=Application.Current.MainWindow, Path=Icon}" >

<Grid>

</Grid>

答案

这应该工作:

<Window ...
   Icon="{Binding Path=MainWindow.Icon, Source={x:Static Application.Current}}">

    <Grid>

    </Grid>
</Window>

以上是关于将Window1图标绑定到MainWindow图标的主要内容,如果未能解决你的问题,请参考以下文章