小编use*_*493的帖子

WPF:自定义+ - 在TreeView中

可以将TreeView控件(+ - )的内置折叠 - 展开图标更改为我自己的图标吗?

提前致谢!

wpf treeview

7
推荐指数
2
解决办法
1万
查看次数

WPF:绑定到ComboBox SelectedItem

我有一个基于XML数据的ComboBox UserControl:

<Root>
<Node Background="Yellow" Foreground="Cyan" Image="1.ico" Property="aaaa" Value="28" />
<Node Background="SlateBlue" Foreground="Black" Image="2.ico" Property="bbbb" Value="2.5" />
<Node Background="Teal" Foreground="Green" Image="3.ico" Property="cccc" Value="4.0" />
<Node Background="Yellow" Foreground="Red" Image="4.ico" Property="dddd" Value="0" /></Root>
Run Code Online (Sandbox Code Playgroud)

这是UserControl XAML:

<UserControl x:Class="xxxxxxxx.MyComboBox"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         x:Name="myComboBoxControl">
<UserControl.Resources>
    <DataTemplate x:Key="dataTemplateNode">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" MinWidth="20"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto" MinWidth="20"/>
            </Grid.ColumnDefinitions>
            <Border Background="{Binding XPath=@Background}" Grid.Column="0">
                <Image Source="{Binding XPath=@Image}" 
                       Width="16" 
                       Height="16" 
                       Margin="3" />
            </Border>
            <Border Background="{Binding XPath=@Background}" Grid.Column="1">
                <TextBlock Foreground="{Binding XPath=@Foreground}" 
                           Margin="3"
                           Text="{Binding XPath=@Property}" />
            </Border>
            <Border Background="{Binding XPath=@Background}" Grid.Column="2"> …
Run Code Online (Sandbox Code Playgroud)

wpf binding combobox

6
推荐指数
2
解决办法
3万
查看次数

WPF:绑定到选定的TreeViewItem

我有一个TreeView建立在XML文件上的文件,每个文件都包含一个文本和一个图像 TreeViewItem.此外,我有一个TextBlock和一个Image,我想绑定到选定的TreeViewItem.

我怎样才能做到这一点?

这是我的XAML:

<Window.Resources>
<HierarchicalDataTemplate DataType="Node" ItemsSource ="{Binding XPath=ChildNode}">
    <StackPanel Orientation="Horizontal">
        <Image Source="{Binding XPath=@Image}"/>
        <TextBlock Text="{Binding XPath=@Name}" />
    </StackPanel>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="ChildNode" ItemsSource ="{Binding XPath=GrandchildNode}">
    <StackPanel Orientation="Horizontal">
        <Image Source="{Binding XPath=@Image}" />
        <TextBlock Text="{Binding XPath=@Name}" />
    </StackPanel>
</HierarchicalDataTemplate>
<DataTemplate DataType="GrandchildNode">
    <StackPanel Orientation="Horizontal">
        <Image Source="{Binding XPath=@Image}" />
        <TextBlock Text="{Binding XPath=@Name}" />
    </StackPanel>
</DataTemplate>
<XmlDataProvider x:Key="xmlNodeList" Source="XMLFile1.xml" XPath="Root"/></Window.Resources><StackPanel>
<TreeView Name="treeView1" ItemsSource="{Binding Source={StaticResource xmlNodeList}, XPath=Node}" />
<TextBlock />
<Image /></StackPanel>
Run Code Online (Sandbox Code Playgroud)

这是一个XML数据:

<Root>
<Node Name="AAA" …
Run Code Online (Sandbox Code Playgroud)

wpf treeview binding hierarchicaldatatemplate

2
推荐指数
1
解决办法
7321
查看次数