WPF ListView ignores SelectedItem-change

I am working with a ListView in WPF (MAHApps styled ListView). I bound the ListView to an observable collection. I bound the SelectedItem-Property to a property of the ViewModel.When I select an item in the ListView via GUI "SelectedItem" is changed. When I change "SelectedItem" in the ViewModel, the ListView only changes, when I set the SelectedItem to NULL. When I set any other (valid!) object (like the first entry of the ObservableCollection) the ListView just ignores it.Furthermore: When I want to "Veto" a SelectedItem Change (because data is not saved), the ListView h...

with MVVM is a good practice to add controls to wrap pannel from the view model?

I have an application in WPF that use the MVVM pattern and I use to have a list or observableCollection for example to binding comboBox, DataGrids... etc. However I have a control and I would like to add dynamically items of this control to the wrap pannel.is a good idea in my view model create the view and view model of this control and add it to the list that is binding to the wrap pannel?If this is not a good idea, how can I add items to the wrap pannel dynamically?Thanks.EDITI add code.I am trying to do it but I don't get the solution.I have a principal view model that ...

Assign different ViewModels to one UserControl

I have MainWindow.xaml page with it's MainViewModeland would like to add 2 SidePanels using one UserControl, but it should have different ViewModels. MainViewModel alredy has 2 properties with created SidePanelViewModels:public MainViewModel(){ LeftSidePanel = new SidePanelViewModel(PanelSides.Left); RightSidePanel = new SidePanelViewModel(PanelSides.Right);}How to set objects in this properties as DataContext for each UserControl in xaml?Something like this doesnot work:<Window DataContext="{Binding MainViewModel, Source={StaticResource Locator}}">... <Gr...

How do I reuse VisualState, VisualStateGroup and VsualStateManager in shared resource?

I created many buttons that it use the same VisualStateManager, VisualStateGroup and VisualState in my Windows Phone project. Then, I want to reuse all of them as the shared resources as the other type of an element such as margin, colors etc.But I found only the way to reuse storyboard that it would be better if I can reuse all of the VisualState. Is there solution of the reusable VisualState? The solution I found I tested on Windows 10 UWP app, I have tested several options like deserializing XAML, cloning, etc, but in the end I found the following is the best solution...

ListBox item align button on right side

I have a listbox with a custom item style. This includes a text box and a settings button. I want the button to always be aligned on the far right of the item. I can't seem to get it to function this way. <ListBox.ItemTemplate> <DataTemplate> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" MinWidth="200"/> <ColumnDefinition Width="25" MinWidth="25" /> </Grid.ColumnDefinitions> <TextBox Grid.Column="0" IsReadOnly="true" Text="{Binding name}"/&...

Custom UserControl Property used by child element

I'm trying to get some WPF concepts down, so I've put together a simple example of what I'm trying to do. I would like to set a custom property of a user control, and have it be used by an element within the control.I've been researching and experimenting, but I'm not fully understanding everything here. Any help would be appreciated.The user control for this example is a simple square with a circle inside of it:<UserControl x:Class="CircleInSquare" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xa...

How to Force Keyboard Focus on a DataGrid?

OLD TITLE: Inconsistent Actions in GridView SelectCell + Focus/Edit (GridView Reloaded Twice?)I'm developing a GridView (bound by Data) set in the Content property of an Expander. When I open the Expander, I want the third column, first element to be selected and editable (but simply focused would be acceptable as well). When I tried to add this functionality to this action attached to Expanded, the grid never selected the first item for me. I did some troubleshooting, and strangely enough, I noticed something occurring. The Expander is part of a template within an ItemsCol...

Trigger is not firing

Been doing trial and error on this all day. Thought it might be better to post here and get some feedback on whether I am doing this the right way or not. I am just trying to change the TextBlock ToolTip text when the radio button is checked.Edit: Figured it out... I applied the Trigger to the DataTemplate instead of the TextBlock itself. (See answer) If you set the text locally the trigger will not be able to change the value due to precedence.Move the default text into the style:<!-- There are still issues with this --><TextBlock Grid.Row="2" Grid.Column="1"&g...

Horizontal Scroll Not Displaying on WrapPanel WPF

I have Custom View here that is having A Wrappanel with Vertical orietiation The Problem is that it does not show horizontal scroll bar...Here is the link for the code...Code for what i am tryingMy Custom View Style<Style x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type CustomView:PlainView}, ResourceId=ImageView}" TargetType="{x:Type ListView}" BasedOn="{StaticResource {x:Type ListView}}"> <Setter Property="ItemContainerStyle" Value="{Binding (ListView.View).ItemContainerStyle, RelativeSource={Relati...

WPF - Bind Orientation property to DockPanel.Dock in ItemsPanelTemplate's StackPanel

I'm building a CustomControl that inherits ItemsControl and have a StackPanel for ItemsPanelTemplate.This is the Style: <Style TargetType="{x:Type MyCustomControl}"> <Setter Property="ItemsPanel"> <Setter.Value> <ItemsPanelTemplate> <StackPanel Orientation="{Binding Path=DockPanel.Dock, Converter={StaticResource PositionToOrientationConverter}}"/> </ItemsPanelTemplate> </Setter.Value> </Setter> <Setter Property="Template"> <Setter.Value> ...

In a datagrid, how do you bind a different ItemsSource for each row when also using a CompositeCollection?

I have a DataGrid where the ItemsSource is bound to an ObservableCollection<DataGrid ItemsSource="{Binding Items}">Each item in the ObservableCollection also has an ObservableCollection of strings.One of the columns is a DataGridTemplateColumn that contains a ComboBox. I would like each row's ComboBox to contain items in the ObservableCollection of strings in that row's ViewModel. If I bind it normally, this works. However, I can't seem to get it to work if I am using a CompositeCollection.<DataGridTemplateColumn Header="Column Title"> <DataGridTemplate...

How to setup datacontext and custom usercontrol binding

I do not understand why binding works for a Textbox but does not work for usercontrol.On image below you see how it should work. The service can bind to the yellow usercontrol and this usercontrol contains a property of my own class. In my case this property is called Email. Problem is, that this Email is never bind to the yellow usercontrol.If I replace the usercontrol by simple "TextBox" control, it works proper.Please can you advice me how to get Binding work?Codebehind of Silvelright Main Page#Region "UserProfile" ''' <summary> ''' UserProfile Dependency Pro...

How can I bind to a non ObservableCollection?

Is there a way to bind directly to a Collection in the model and manually tell WPF that the binding needs refreshing without having to create an ObservableCollection for it in the viewmodel?<ListBox ItemsSource="{Binding Position.PossibleMoves}">...</ListBox>Position is my model, part of a chess library, and PossibleMoves is a Collection within it. I do not want to implement INotifyProperty changed or put ObservableCollections in a stand alone optimized library.I want to avoid copying PossibleMoves into an ObservableCollection every time the position is updated....

WindowsStore ComboBox SelectedIndex not being properly updated?

I have a ComboBox that is binded to my ViewModel. The SelectedIndex is binded to a property on the ViewModel. What I want to do is, with some conditions, some of the choices on the Index becomes invalid so that when the user tries to select it, it should show an error message and not change the currently selected item.On the back-end, all is well. However, on the UI, the SelectedIndex of the ComboBox still changes. The error message shows properly, but then the 'shown' selected item in the combobox is not the proper one (ex. ComboBox is currently 'Item 4', User selects inva...

Bind SelectedItems from two Listboxes into one Listbox

How can I bind SelectedItems from two ListBoxes to one Listbox?I'm using MVVM pattern and I set binding for SelectedItems for two ListBoxes to property in my ViewModel:<ListBox SelectedItemsList="{Binding EmployeeViewM.SelectedAll, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}"/>Then I bind SelectedAll property as an ItemsSource for my third ListBox:<ListBox ItemsSource="{Binding EmployeeViewM.SelectedAll, Mode=TwoWay}" SelectionMode="Single" >The property on my ViewModel:Private _selectedAll As IList = New ArrayList()Public Property SelectedAll() As...

Why can't I use the Name attribute on UserControl in the same assembly?

When I created a WPF UserControl and tried to use it, I got the following compiler error: Because 'UserControl1' is implemented in the same assembly, you must set the x:Name attribute rather than the Name attribute.The message is clear on what to do to fix it, but what is its cause? Why can't I use Name here? x:Name is simply a more explicit way of saying "The name attribute in this specific XML namespace". The fact that WPF can't compile it without being given this hint because it's in the same assembly is just a limitation of how they wrote the parser.If you are aski...

Page 1 of 155  |  Show More Pages:  Top Prev Next Last