因为一个愚蠢的问题,两天来我真的很生气。我已经在这里提出了这个问题,但似乎我的问题迷失了,没有人会再看到它。我的问题很简单:
我有一个包含CustomControl (库项目)的项目,这个自定义控件代码是从窗口控件继承的。所以它有一个继承下来的图标属性。在创建控件设计的XAML代码中,我希望在我的ResourceDictionary中放置一个绑定到图标属性的图像。
...    
<Image Grid.Column="0" Margin="3" Width="27" Height="27" Source="{Binding Icon}" />
...然后,我有第二个项目( WPF应用程序项目)引用我的第一个项目,并使用这个自定义控制窗口,其中设置了Icon属性。图标属性的设置是正确的,因为我可以在任务栏中看到图标,但是图像没有出现,看起来我的绑定不起作用。
<SILU:FlatForm x:Class="SILU_MovieManager.WinMain"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:SILU="clr-namespace:SILU_Controls;assembly=SILU_Controls"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="SILU Movie Manager" Height="425" Width="682" Loaded="FlatForm_Loaded" Icon="/SILU_MovieManager;component/Resources/Images/Film.ico">
    <Grid>
    </Grid>
</SILU:FlatForm>我真的不知道如何绑定,这是我在这里找到的一个解决方案,但是不适合我的。(Solution)
发布于 2010-04-12 09:13:43
我还没有尝试过这个解决方案,这是通过代码和图标实现的
<Window x:Class="WPFWindowAPP.IconLoader"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="WPFWindowAPP" Height="164" Width="405"
>
<Canvas>
    <Button Name="btn" Click="btnClick" Canvas.Top="40" Canvas.Right="90" Width="75">Load Icon</Button>
    <Image Name="icoDisplay" Canvas.Left="10" Canvas.Top="80" Stretch="None" />
</Canvas>
    void btnClick(object sender, RoutedEventArgs e)        {IconImage.ExtractAssociatedIcon(filePath.Text);位图bmp = ico.ToBitmap();MemoryStream strm =新MemoryStream();bmp.Save(strm,System.Drawing.Imaging.ImageFormat.Png);
       BitmapImage bmpImage = new BitmapImage();  bmpImage.BeginInit();       strm.Seek(0, SeekOrigin.Begin);             bmpImage.StreamSource = strm;             bmpImage.EndInit();  icoDisplay.Source = bmpImage; }https://stackoverflow.com/questions/2620733
复制相似问题