本文介绍了绑定组合框图像 - 如何选择组合框图像中保存的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
i有组合框来查看我从数据库读取的图像,绑定工作正常,
但问题是我无法选择我保存在数据库中的图像
但是当点击组合框时,我可以看到所有图像连接
i使用RelativeSource但同样的问题。组合框不选择项目,
请注意我在此控件的构造函数中设置了DataContext
请检查下面的代码:
xaml代码:
i have combobox to view images i read them from database and the binding is work fine,
but the problem that i cann't select the image that i saved in database
but when click the combobox, i can see all images itams
i use RelativeSource but the same problem. combobox not selection the item,
please note the i set the DataContext in constructor of this control
please check my code below:
xaml code:
<UserControl x:Class="TailorManager.Views.OrderDetailItem"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:vm="clr-namespace:TailorManager.ViewModels"
xmlns:Converter="clr-namespace:TailorManager.Converters"
mc:Ignorable="d"
d:DesignHeight="730" d:DesignWidth="556" FlowDirection="RightToLeft" >
<UserControl.Resources>
<!--<vm:OrderDetailItemViewModel x:Key="OrderDetailItemViewModel1" />-->
<Converter:ImageConverter x:Key="ImgConverter" />
</UserControl.Resources>
<Grid >
<ScrollViewer VerticalScrollBarVisibility="Auto" >
<ItemsControl>
<StackPanel>
<GroupBox Header="تفاصيل الياقة" Margin="5,5,5,0" VerticalAlignment="Top" Height="170">
<Grid>
<ComboBox SelectedValue="{Binding Path=OrderDetailItem.CollarTypesImage,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" ItemsSource="{Binding Path= DataContext.ImagesCollarTypes, RelativeSource={RelativeSource AncestorType= UserControl,AncestorLevel=1}}" Margin="393,106,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="132" Height="38">
<ComboBox.ItemTemplate>
<DataTemplate>
<Image Width="50" Height="50" Source="{Binding Path= CollarImage,Converter={StaticResource ImgConverter} }" />
</DataTemplate>
</ComboBox.ItemTemplate >
</ComboBox>
</Grid>
</GroupBox>
<Grid/>
</StackPanel>
</ItemsControl>
</ScrollViewer>
</Grid>
</UserControl>
i将此控件用于这样的窗口:
i use this control into windows like this:
<Window
...
x:Class="TailorManager.Views.AddOrder"
Title="AddCustomer" FlowDirection="RightToLeft" >
<Window.Resources>
<vm:ManageOrderDetilsViewModel x:Key="ManageOrderDetilsViewModel1" />
</Window.Resources>
<Grid DataContext="{StaticResource ManageOrderDetilsViewModel1}" x:Name="GridDataContaner">
<Grid.Background>
<LinearGradientBrush x:Uid="LinearGradientBrush_1" EndPoint="00,1" StartPoint="0.5,0">
<GradientStop x:Uid="GradientStop_1" Color="#FFC6C6FF" Offset="0" />
<GradientStop x:Uid="GradientStop_2" Color="White" Offset="1" />
<GradientStop x:Uid="GradientStop_3" Color="White" Offset="0.72" />
</LinearGradientBrush>
</Grid.Background>
<GroupBox Header="تفاصيل الطلب" Margin="10,160,10,0" FlowDirection="RightToLeft">
<Grid Grid.Column="0" Name="GridOrderDetails">
...
<Grid Grid.Column="1">
<Border BorderBrush="Black" BorderThickness="2" CornerRadius="3" Margin="4" >
<Grid>
<local:OrderDetailItem x:Name="OrderDetailItemControl" VerticalAlignment="Top" />
</Grid>
</Border>
</Grid>
</Grid>
</GroupBox>
</Grid>
</Window>
推荐答案
这篇关于绑定组合框图像 - 如何选择组合框图像中保存的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!