影像装订 [英] Image binding
本文介绍了影像装订的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试自定义组合框,因此我编辑了它的模板,因此我总是可以在组合框的标题中显示图像,我通过在模板中放置Image而不是ContentPresenter来进行管理,但是它是一个模板,因此我将创建一些来自它的组合框,每个组合框都有自己的图像,我如何管理呢?使用每个新的组合框,我都可以设置自己的图像?
(对不起,我的英语!):
Hi,
I''m trying to customize combobox, I edited its template so I can always display an image in the header of the combobox, I managed this by putting Image instead of ContentPresenter in the template, but its a template and I will create number of comboboxes from it and each have its own image, HOW I can manage that, with each new combobox i can set its own image??
(sorry for my English!):
<ControlTemplate TargetType="ComboBox" x:Key="CustomBTemplate">
<Grid>
<Border x:Name="ContentPresenterBorder">
<Grid>
<ToggleButton x:Name="DropDownToggle" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="-1" HorizontalContentAlignment="Right">
<Path x:Name="BtnArrow" Height="4" Width="8" Stretch="Uniform" Margin="0,0,6,0" Fill="Black"
Data="F1 M 300,-190L 310,-190L 305,-183L 301,-190 Z " />
</ToggleButton>
<Image Width="35" Height="35" Source="somepicture.png" HorizontalAlignment="Left"/>
</Grid>
</Border>
<Popup x:Name="Popup">
<Border x:Name="PopupBorder" HorizontalAlignment="Stretch" Height="Auto" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="Black" Background="White" CornerRadius="3">
<ScrollViewer x:Name="ScrollViewer" BorderThickness="0" Padding="1">
<ItemsPresenter/>
</ScrollViewer>
</Border>
</Popup>
</Grid>
</ControlTemplate>
推荐答案
您需要创建一个AttachedDependencyProperty,将其应用于ComboBox的顶层,然后在ControlTemplate中与之绑定类似的东西:
You need to create an AttachedDependencyProperty that you''ll apply to the top level of the ComboBox and then in your ControlTemplate you''ll bind to with something like:
<Image Width="35" Height="35" Source="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(y:MyClass.ComboImage)}" HorizontalAlignment="Left"/>
您可以在此处的技巧中找到一些与笔刷非常相似的东西. [ ^ ].
You can find something very similiar dealing with brushes in my tip here.[^].
这篇关于影像装订的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文