如何在Wpf中将图像添加到UserControl菜单

时间:2018-03-07 14:02:42

标签: wpf image mvvm

enter code here<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:EPOS.Desktop.View" 
     xmlns:vm="clr-namespace:EPOS.Desktop.ViewModel"
     xmlns:UserControls="clr-namespace:EPOS.Desktop.UserControls"
     xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core" xmlns:dxwui="http://schemas.devexpress.com/winfx/2008/xaml/windowsui" xmlns:dxn="http://schemas.devexpress.com/winfx/2008/xaml/navbar" x:Class="EPOS.Desktop.View.MainSaleUI"

    mc:Ignorable="d"
    Title="MainSaleUI"

    Width="1046" Height="500" Left="500" Top="500"
    Background="SkyBlue" 
    WindowStartupLocation="CenterScreen"
    >


<Window.Resources>

    <DataTemplate DataType="{x:Type vm:QeueOrdersViewViewModel}">
        <UserControls:QeueOrders />

    </DataTemplate>

    <DataTemplate DataType="{x:Type vm:TillViewModel}">
        <UserControls:TillUC/>
    </DataTemplate>

    <DataTemplate DataType="{x:Type vm:SettingViewModel}">
        <UserControls:Settings/>
    </DataTemplate>

</Window.Resources>

<Grid Margin="0,67,65,0">

    <Grid.ColumnDefinitions>
    <ColumnDefinition/>
    <ColumnDefinition Width="3*"/>
</Grid.ColumnDefinitions>

<ListBox x:Name="ListBoxMenu"                    
             Grid.Column="0" Margin="5"
             ItemsSource="{Binding Settings}"
             SelectedIndex="0">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Name}" Padding="10"/>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

<Border Grid.Column="1" Margin="5,5,10,5" BorderBrush="#FF7F9DB9" BorderThickness="1">
    <ContentControl Content="{Binding ElementName=ListBoxMenu, Path=SelectedItem}" Margin="0,0,225,0"/>
</Border>

</Grid>

  

块引用

如何在Wpf中将图像添加到用户控制菜单。这些是动态菜单。有没有办法将图像添加到每个文本?

1 个答案:

答案 0 :(得分:1)

我不确定你究竟想要什么......假设你想在列表框上的文字之后/之前显示一些图像,你可以在你的&#34;设置中添加一个图像属性&#34 ; class(对Listbox的物品来源进行绑定)并使用以下内容更改列表框的datatemplate内容:

            <StackPanel>
                <TextBlock Text="{Binding Name}" Padding="10"/>
                <Image Source="{Binding Image }" />
            </StackPanel>