有谁知道如何从 TreeView 获取 SelectedItem(不是标题)?
这是我的代码:
<TreeView Name="treeView1" DataContext="{Binding Path=PresentationsViewModel}" Grid.Column="1" >
    <TreeViewItem IsExpanded="True" Header="Objects-A-List" DisplayMemberPath="Name" ItemsSource="{Binding Path=MyItem.ListA}"></TreeViewItem>
    <TreeViewItem IsExpanded="True" Header="Objects-B-List" DisplayMemberPath="Name" ItemsSource="{Binding Path=MyItem.ListB}"></TreeViewItem>
    <TreeViewItem IsExpanded="True" Header="Objects-C-List" DisplayMemberPath="Name" ItemsSource="{Binding Path=MyItem.ListC}"></TreeViewItem>
</TreeView>
Run Code Online (Sandbox Code Playgroud)
请注意,有 3 个不同的列表,包含 3 个不同的对象类型。拥有以下内容对我有很大帮助:
public Object SelectedObject
{
    set { _selectedObject = value; RunMyMethod(); RaisePropertyChanged("SelectedObject"); }
}  
Run Code Online (Sandbox Code Playgroud) 我有一个wpf c#应用程序,它将任务从文本文件加载到treeView,有关任务的数据正在加载到列表中,我试图删除列表中位置I的数据,但我无法弄清楚如何.我有这个循环检查,以查看所选的treeView项是否等于列表中位置I的项目,如果是这样,我想从列表中删除该项.下面是对环路的作品,我只是不知道如何做实际删除,我试过的东西,如.delete和.remove我的msdna找到.
for (int i = 0; i < name.Count; ++i)
{
       string selectName = ((TreeViewItem)(treeView1.SelectedItem)).Header.ToString();
       if (selectName == name[i])
       {
       //name.Remove(i) or name.Remove[i] or name[i].Remove
       }
}
Run Code Online (Sandbox Code Playgroud) 我有Html下拉.我想在单行使用jquery选择"11:00 pm"标记我该怎么办?
<select name="timing" id="timing" >
      <option value="00:00 am">Midnight</option>
      <option value="11:00 pm">11 pm</option>
      <option value="10:00 pm">10 pm</option>
      <option value="09:00 pm">9 pm</option>
      <option value="08:00 pm">8 pm</option>
    </select>
Run Code Online (Sandbox Code Playgroud) 我有一个TreeView组件和内容,如下所示:
MainLine  
  + SubLine1 
  + SUbline2
  + Subline3
  + Subline4
  + Subline5
  - Subline6
      SublineDetail1
      **SublineDetail2**
      SublineDetail3
假设SublineDetail2已经选中,我希望将它的完整路径作为字符串传递给文本框,就像这个"(1.6.2)".
我怎样才能做到这一点?
我有一个列表框绑定到 ObservableCollection of Items。每个 listboxItem 包含一些文本块和一些按钮。我想仅在选择或突出显示列表框项目时才显示列表框项目内的按钮。如果列表框项目未突出显示,则应隐藏该按钮。我尝试使用 datatrigger 绑定到 IsSelected 属性。然而它不起作用。请指教。谢谢
        <ListBox Name="LayoutListBox" SelectedItem="{Binding Path=SelectedLayout, Mode=TwoWay}" ItemsSource="{Binding Layouts}" SelectionMode="Single" HorizontalContentAlignment="Stretch">
      <ListBox.ItemContainerStyle>
        <Style TargetType="ListBoxItem">
          <Style.Resources>
            <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Gray"/>
            <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Gray"/>
          </Style.Resources>
        </Style>
      </ListBox.ItemContainerStyle>
      <ListBox.ItemTemplate>
        <DataTemplate>
          <Grid>
            <Grid.RowDefinitions>
              <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Border HorizontalAlignment="Stretch" Margin="2" CornerRadius="2" BorderBrush="#80808080" BorderThickness="1" Background="GhostWhite">
                    <Grid>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="*" />
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height ="*"/>
                                    <RowDefinition Height ="*"/>
                                </Grid.RowDefinitions>
                                <DockPanel Grid.Row="1" Grid.Column="3" DockPanel.Dock="Right">
                                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" …Run Code Online (Sandbox Code Playgroud) @Override
    public void onBindViewHolder(final mainscreenspecializationadap.MyViewHolder holder, final int positionz) {
        this.position = holder.getAdapterPosition();
        final specializationpojo album = albumList.get(holder.getAdapterPosition());
        holder.txtspecs.setText(album.getSplztnname());
        holder.imgspecs.setImageResource(album.getIcon());
    holder.linelayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            row_index=positionz;
            album.setOpened(!album.isOpened());
            notifyDataSetChanged();
        }
    });
    if(positionz==row_index){
        holder.imageView.setBackground(mContext.getResources().getDrawable(R.drawable.white_circle_background));
        holder.txtspecs.setSelected(true);
        if (type==1)
        {
            onClick.onSelected(row_index,album.isOpened(),album.isClosed());
        }
        else if(type==2)
        {   onClick.onSpecialisationSelected(album.getSplzcode(),album.getCount());
        }
    }
    else
    {
        holder.txtspecs.setSelected(false);
        holder.imageView.setBackground(mContext.getResources().getDrawable(R.drawable.green_background));
    }
}
Run Code Online (Sandbox Code Playgroud)
I have a recycler view where I need to select only one item, so on that basis, I have to show a sub list items.
Now …
android listview selecteditem background-color android-recyclerview
我在AS3电影的舞台上有一个列表组件.我在运行时使用值填充它,用户可以选择多个值.
单击一个按钮时,我希望列表重置为未选择任何内容的状态,我只能想出将所选索引设置为0并将列表中的第一个位置留空或读取"从列表中选择"如果选中,则使代码忽略此项.
有没有办法将列表(和组合框组件)重置为任何选定的.
谢谢
是否可以ListBoxItem在Windows Presentation Foundation中更改从Code-Behind中选择的内容?
这是一个很简单的任务真的,我有一个Next和Previous按钮,它们代表了下一个和上一个项目ListBox.但是,myListBox.items当然是我存储在内容中的对象表示ListBox.
那么,如何获取ListBoxItem设置IsSelected属性?
我在数据模板中使用了一个列表框 - 从早期的帖子中我无法直接在后面的代码中引用列表框.
因此,我正在捕获列表框的selectionchanged事件中的最后一个选定对象,并在我想要导航时使用它.
我现在还需要清除列表框中的选定对象 - 我可以在selectionchanged事件中执行此操作(在将其存储之后).
或者我可以在列表框上使用MouseLeftButtonDown事件(我理解它相当于'click')但是我可以在此事件中获取列表框中的选定对象.
我不明白为什么在我的以下示例中,"Billing Model"组合框在文本框中没有显示属性BillingModel.BillingModelDescription.选择客户端后,我希望组合框显示当前的billng模型描述,但它保持空白.绑定到同一事物的文本框确实显示了描述.我有一些可能的模型作为ItemsSource,它工作正常.如何在选择客户端时更新计费模型组合框?
这是XAML:
<Window x:Class="WpfApplication7.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
<StackPanel>
    <StackPanel Orientation="Horizontal">
        <Label Content="Client"/>
    <ComboBox ItemsSource="{Binding AllClientData}" DisplayMemberPath="EmployerStr"
              SelectedItem="{Binding SelectedClient}"
              Width="300"/>
    </StackPanel>
    <StackPanel Orientation="Horizontal">
        <Label Content="Billing Model:"/>
    <ComboBox ItemsSource="{Binding AllBillingModels}" DisplayMemberPath="BillingModelDescription"
              SelectedItem="{Binding SelectedClient.BillingModel}"
              Width="300"/>
    </StackPanel>
    <StackPanel Orientation="Horizontal">
        <Label Content="Billing Model" />
    <TextBox Text="{Binding SelectedClient.BillingModel.BillingModelDescription}" Width="200"/>
    </StackPanel>
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
代码隐藏(这只是一个例子,我在完整的应用程序中使用MVVM等,但这是我用来说明问题):
public partial class MainWindow : Window, INotifyPropertyChanged
{
    public MainWindow()
    {
        AllClientData = new ObservableCollection<ClientRate>();
        AllBillingModels = new ObservableCollection<BillingModelType>();
        ClientRate uno = new ClientRate();
        uno.BillingModel = new BillingModelType();
        uno.BillingModel.BillingModelID = 3; …Run Code Online (Sandbox Code Playgroud)