相关疑难解决方法(0)

WPF组合框:文本框和下拉列表中的不同模板

这是我的组合框.

    <ComboBox Height="45" HorizontalAlignment="Left" Margin="184,66,0,0" Name="ComboBox1" VerticalAlignment="Top" Width="216">
        <ComboBox.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal">
                    <Label Content="{Binding FullName}" Width="150" />
                    <Label Content="{Binding Title}" Width="100"/>
                    <Label Content="{Binding BranchName}" />
                </StackPanel>
            </DataTemplate>
        </ComboBox.ItemTemplate>
    </ComboBox>
Run Code Online (Sandbox Code Playgroud)

如何更改它,以便只有FullName出现在组合框的文本框部分中,而所有三列仍然出现在下拉部分?

c# wpf xaml combobox

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

在ComboBox中以不同方式显示所选项目

我有一个组合框,我在其中设置了ItemTemplate如下所示的内容:

<ComboBox.ItemTemplate>
  <DataTemplate>
    <StackPanel Orientation="Horizontal">
      <TextBlock Text="{Binding Piece.NoPiece}" Width="50" />
      <TextBlock Text="{Binding Piece.Description}" Width="170" />
      <TextBlock Text="{Binding Piece.Categorie.NomCategorie}" />
    </StackPanel>
  </DataTemplate>
</ComboBox.ItemTemplate>
Run Code Online (Sandbox Code Playgroud)

如您所见,我有三列让用户看到不同的信息.但是,我希望组合中的选定项目仅显示第二列.换句话说,有一种方法可以ItemTemplate在向下滚动时以不同的方式显示项目,而在它关闭时只显示选择吗?

.net wpf combobox selecteditem

3
推荐指数
1
解决办法
4264
查看次数

仅在选择ListViewItem时显示内容

ListBoxListBoxItems我选择其中一个时,我想改变按钮"View"的可见性并显示它.意味着默认状态为隐藏.

这是可能的,如果是这样,我是用XAML中的触发器还是后面的代码解决这个问题?

XAML片

<ListBox Background="Transparent" 
      ItemContainerStyle="{StaticResource listBoxTemplate}" BorderThickness="0">
    <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
            <StackPanel Orientation="Vertical" VerticalAlignment="Center" />
        </ItemsPanelTemplate>
    </ListBox.ItemsPanel>
    <ListBox.ItemTemplate>
        <DataTemplate>
            <Grid Background="Beige" Margin="10 10 10 10" 
                    HorizontalAlignment="Center" Width="500" Height="100"
                    VerticalAlignment="Stretch">
                <Grid.RowDefinitions>
                    <RowDefinition Name="TopRow" Height="50" />
                    <RowDefinition Name="BottomRow" Height="*" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Name="LeftSideMenu" Width="*"/>
                    <ColumnDefinition Name="Middle" Width="*"/>
                </Grid.ColumnDefinitions>
                <Label Grid.Column="0" Grid.Row="0" Content="{Binding name}" />

                <Button Grid.Column="1" VerticalAlignment="Center" 
                    Grid.RowSpan="2" Name="view" Click="viewClicked_Click"
                    Grid.Row="0">View</Button>

                <Label Grid.Column="0" Grid.Row="1" 
                    Content="{Binding description}" />
            </Grid>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>
Run Code Online (Sandbox Code Playgroud)

c# wpf listbox selecteditem

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

标签 统计

wpf ×3

c# ×2

combobox ×2

selecteditem ×2

.net ×1

listbox ×1

xaml ×1