将Window1图标绑定到MainWindow图标

时间:2018-03-01 16:00:17

标签: wpf xaml

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

<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>

1 个答案:

答案 0 :(得分:0)

这应该有效:

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

    <Grid>

    </Grid>
</Window>