Silverlight 从代码隐藏在上下文菜单中设置图标图像源时出现问题
我在UserControl中有一个DataGrid,并且向DataGrid添加了一个ContextMenu XAML如下所示:Silverlight 从代码隐藏在上下文菜单中设置图标图像源时出现问题,silverlight,image,silverlight-4.0,contextmenu,Silverlight,Image,Silverlight 4.0,Contextmenu,我在UserControl中有一个DataGrid,并且向DataGrid添加了一个ContextMenu XAML如下所示: <sdk:DataGrid ItemsSource="{Binding Path=GridSource}"> <sdk:DataGrid.Columns> <sdk:DataGridTextColumn Binding="{Binding Path=Name, Mode=OneWay}" Header="Name"/
<sdk:DataGrid ItemsSource="{Binding Path=GridSource}">
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn Binding="{Binding Path=Name, Mode=OneWay}" Header="Name"/>
<sdk:DataGridTextColumn Binding="{Binding Path=Number, Mode=OneWay}" Header="Number"/>
</sdk:DataGrid.Columns>
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu Opened="ContextMenu_Opened">
<toolkit:MenuItem IsEnabled="False">
<toolkit:MenuItem.Icon>
<Image x:Name="menuIcon"/>
</toolkit:MenuItem.Icon>
</toolkit:MenuItem>
<toolkit:Separator />
<toolkit:MenuItem Header="View Agent Route" Click="AgentRoute_Click"/>
<toolkit:MenuItem Header="Live Track" Click="LiveTrack_Click"/>
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
</sdk:DataGrid>
没有显示任何内容,我没有收到任何错误或任何它没有显示的内容。我用同样的方法在我的应用程序的其他地方设置了一个ImageSource(使用相同的实际*.png文件),你知道这里发生了什么吗
这是因为它是一个上下文菜单吗?在网格上?我搞不清楚发生了什么。尝试使用:-
new Uri("/Assets/Images/user_green.png", UriKind.Relative")
一般来说,我会尽量避免使用“.”父路径,如果可能的话,它们只会引起头痛。您知道Xap的根目录下有一个Assets文件夹,因此请从“/Assets”开始,然后从那里开始操作。尝试使用:-
new Uri("/Assets/Images/user_green.png", UriKind.Relative")
一般来说,我会尽量避免使用“.”父路径,如果可能的话,它们只会引起头痛。您知道在Xap的根目录下有一个Assets文件夹,所以从“/Assets”开始,然后从那里开始。我使用contextmenu_opened事件中的一个来实现这一点
private void ContextMenu_Opened(object sender, RoutedEventArgs e)
{
ImageSourceConverter converter = new ImageSourceConverter();
menuIcon.Source = (ImageSource)converter.ConvertFromString("../../Assets/Images/user_green.png");
}
我在contextmenu_Open事件中使用了一个
private void ContextMenu_Opened(object sender, RoutedEventArgs e)
{
ImageSourceConverter converter = new ImageSourceConverter();
menuIcon.Source = (ImageSource)converter.ConvertFromString("../../Assets/Images/user_green.png");
}
你必须通过一个图像。这对我很有用:
var mus = new MenuItem {
Header = "Unicorns...",
Icon = new Image {
Source = new BitmapImage(new Uri("/myApp;component/img/unicorns.png",UriKind.Relative))
}
};
你必须通过一个图像。这对我很有用:
var mus = new MenuItem {
Header = "Unicorns...",
Icon = new Image {
Source = new BitmapImage(new Uri("/myApp;component/img/unicorns.png",UriKind.Relative))
}
};
我试过了,但还是不行。你能想出为什么它在通过XAML设置而不是通过代码隐藏时工作吗?试过了,但仍然不工作。您能想到为什么它在通过XAML设置而不是通过代码隐藏时工作吗?