selecteditem

Mvvm-Light Silverlight, using EventToCommand with a Combobox

瘦欲@ 提交于 2019-11-28 21:27:22
问题 I've hooked up a ComboBox's SelectedItemChangeEvent to a ICommand in my view model. Everything seems to be working fine however I do not know how to get the SelectedItem of the ComboxBox. I think I need to use the CommandParameter of the EventToCommand - do I bind this to something in my ViewModel that has the selectedItem of the ComboBox? I've tried this: <ComboBox Width="422" Height="24" DisplayMemberPath="Name" ItemsSource="{Binding CategoryTypes}" SelectedItem="{Binding SelectedCategory}"

ComboBox ItemsSource changed => SelectedItem is ruined

允我心安 提交于 2019-11-28 21:15:39
Ok, this has been bugging me for a while now. And I wonder how others handle the following case: <ComboBox ItemsSource="{Binding MyItems}" SelectedItem="{Binding SelectedItem}"/> The DataContext object's code: public ObservableCollection<MyItem> MyItems { get; set; } public MyItem SelectedItem { get; set; } public void RefreshMyItems() { MyItems.Clear(); foreach(var myItem in LoadItems()) MyItems.Add(myItem); } public class MyItem { public int Id { get; set; } public override bool Equals(object obj) { return this.Id == ((MyItem)obj).Id; } } Obviously when the RefreshMyItems() method is called

How to cast a System.Windows.Controls.SelectedItemCollection?

谁都会走 提交于 2019-11-28 17:23:32
I have a method: private void DeletePuzzle(object param) { } param is a System.Windows.Controls.SelectedItemCollection , that I got from a WPF ListView 's SelectedItems property. Somehow, I can't seem to cast it from an object to anything useful. I can't create a System.Windows.Controls.SelectedItemCollection because of its protection level, and param won't cast to IList , ICollection or IEnumerable . How can I iterate through param's items? Matt Searles Right, got it sorted. I kept trying to cast it like IList<PuzzleViewModel> collection = (IList<PuzzleViewModel>)param; Which told me it

Get Selected TreeViewItem Using MVVM

≡放荡痞女 提交于 2019-11-28 06:00:10
So someone suggested using a WPF TreeView , and I thought: "Yeah, that seems like the right approach." Now, hours and hours later, I simply can't believe how difficult it has been to use this control. Through a bunch of research, I was able to get the TreeView` control working, but I simply cannot find the "proper" way to get the selected item to the view model. I do not need to set the selected item from code; I just need my view model to know which item the user selected. So far, I have this XAML, which isn't very intuitive on its own. This is all within the UserControl.Resources tag:

WPF binding to Listbox selectedItem

泄露秘密 提交于 2019-11-28 05:48:38
Can anyone help with the following - been playing about with this but can't for the life of me get it to work. I've got a view model which contains the following properties; public ObservableCollection<Rule> Rules { get; set; } public Rule SelectedRule { get; set; } In my XAML I've got; <ListBox x:Name="lbRules" ItemsSource="{Binding Path=Rules}" SelectedItem="{Binding Path=SelectedRule, Mode=TwoWay}"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <TextBlock Text="Name:" /> <TextBox x:Name="ruleName"> <TextBox.Text> <Binding Path="Name" UpdateSourceTrigger=

Binding ComboBox.SelectedItem in Silverlight

巧了我就是萌 提交于 2019-11-28 04:23:59
问题 This one is driving me crazy. Here's the XAML: <UserControl x:Class="SilverlightApplication1.Page" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Grid x:Name="LayoutRoot" Background="White"> <StackPanel HorizontalAlignment="Left" VerticalAlignment="Top"> <ComboBox ItemsSource="{Binding Path=Thing.Stuff}" SelectedItem="{Binding Path=Thing.SelectedStuff}"> <ComboBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding

WPF: Select TreeViewItem broken past the root level

雨燕双飞 提交于 2019-11-28 02:15:18
问题 I'm trying to select a TreeViewItem by ID, but having problems getting it to work past the first (root) level. I've done so much reading round on this and am using the method below. private static bool SetSelected(ItemsControl parent, INestable itemToSelect) { if(parent == null || itemToSelect == null) { return false; } foreach(INestable item in parent.Items) { if(item.ID == itemToSelect.ID) { // just comparing instances failed TreeViewItem container = parent.ItemContainerGenerator

WPF Listview Access to SelectedItem and subitems

≯℡__Kan透↙ 提交于 2019-11-28 01:50:23
Ok, I am having more problems with my C# WPF ListView control. Here it is in all its glory: <Window x:Class="ebook.SearchResults" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"Title="ISBNListView" Height="503" Width="1004"> <Grid> <ListView Name="listView1" Margin"22,30,33,28" MouseDoubleClick="getSelectedItem" > <ListView.View> <GridView> <GridView.Columns> <GridViewColumn Header="ISBN" Width="150" DisplayMemberBinding="{Binding ISBN}"/> <GridViewColumn Header="Title" Width="350" DisplayMemberBinding="{Binding Title}"/>

ListBox Selected Item Background

时间秒杀一切 提交于 2019-11-28 01:41:34
I'm trying to change the background of the selected item in a WPF ListBox. I have attempted to implement a style for it, but for some reason it's not being applied. I still get a blue background. Can anyone see why? <UserControl x:Class="Thumbnails" xmlns:local="clr-namespace:ContentPresenter" 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" mc:Ignorable="d" d:DesignHeight="350" d:DesignWidth=

Change the Selected Color Listbox

最后都变了- 提交于 2019-11-28 01:37:46
问题 I want to change the Selected Background and have it display a gradient with round corners. I've searched Google and found that some people do change the selected color by overriding the default color. Is there any way I can do this? I was thinking is there any way to display a round cornered border as the background when an item is selected? 回答1: Here is the default style for a ListBoxItem (which is what we want to change). This style can be "retrieved" if you are using Expression Blend 4 by