将Window1图标绑定到MainWindow图标

问题描述 投票:1回答:1

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

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

wpf xaml
1个回答
0
投票

这应该工作:

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

    <Grid>

    </Grid>
</Window>
© www.soinside.com 2019 - 2024. All rights reserved.