Xaml - radiobutton标签作为图像?

时间:2015-11-16 13:59:12

标签: c# wpf xaml radio-button

到目前为止,我需要将自定义图片而不是SymbolIcon设置为RadioButton Tag属性:

Home.Tag = new BitmapImage(new Uri("ms-appx:///Assets/my_asset.png"));

Home是我的无线电按钮的名称;

不要工作,有人可以帮忙吗?

2 个答案:

答案 0 :(得分:0)

试试这个

var b = new BitmapImage();
b.BeginInit();
b.UriSource = new Uri(@"ms-appx:///Assets/my_asset.png", UriKind.RelativeOrAbsolute);
b.EndInit();
Home.Tag = b;

答案 1 :(得分:0)

要在单选按钮中设置图像而不是使用内容标记设置XAML,如下所示: -

                    <StackPanel x:Name="rbMode2" Orientation="Horizontal" HorizontalAlignment="Center" Margin="5" Visibility="Collapsed">
                    <RadioButton x:Name="rbDrive1" Tag="Drive" IsChecked="true" Margin="5,0,0,0" 
                                GroupName="ShowSaveRoute" Tapped="RadioRouteMode_Tapped">
                        <StackPanel>
                            <Image Source="ms-appx:///images/Car.png" />
                        </StackPanel>
                    </RadioButton>
                    <RadioButton x:Name="rbWalk1" Tag="Walk" Margin="5,0,0,0" 
                                GroupName="ShowSaveRoute" Tapped="RadioRouteMode_Tapped">
                        <StackPanel>
                            <Image Source="ms-appx:///images/Walking.png" />
                        </StackPanel>
                    </RadioButton>
                    <RadioButton x:Name="rbFly1" Tag="Fly" Margin="5,0,0,0"  
                                GroupName="ShowSaveRoute" Tapped="RadioRouteMode_Tapped">
                        <StackPanel>
                            <Image Source="ms-appx:///images/Airplane.png" />
                        </StackPanel>
                    </RadioButton>
                </StackPanel>

项目图像文件夹中保存的图像