|
If the content is just simple text, and you have bound it to the property, simply raise the PropertyChanged event on this property once you have updated it's text.
|
|
|
|
|
Text="{Binding Content}" with the proper Content should work for you.
Text is a dependency property and you can bind a property to it.
|
|
|
|
|
How to take mouse down event in ViewModel.
|
|
|
|
|
You don't. That's not what you use a ViewModel for. What you would normally do is create a command in your ViewModel and then hook it up to an event in your XAML using something like Laurent Bugnion's EventToCommand[^].
|
|
|
|
|
Use a command or an attached behaviour to handle mouse down.
As a last resort, you can call the viewmodel mouse down method from the view's click event.
However, this is not an MVVM way to handle events in xaml based programming.
|
|
|
|
|
Do you have any code for the same, can you please share it..
|
|
|
|
|
|
If you don't want to complicate things you can always just respond to the MouseDown event in your view's code behind. Here you have access to your ViewModel (via the DataContext) so can 'tell' your ViewModel to perform some action (whether via a command or a property or method - whatever works for you)
MVVM # - I did it My Way
___________________________________________
Man, you're a god. - walterhevedeich 26/05/2011
.\\axxx
(That's an 'M')
|
|
|
|
|
That is the way we set it up, that and navigate being the only code behind. Still it seems to break the fanatical MVVM design.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote: fanatical
Le mot juste!
When I have queried such fanatics, the best real reason I can get out of them is that it stops 'bad programmers' putting non UI code in the View
I am insulted by this, personally. I don't do bad code (that often)
I'm all for maintainability, and two or three lines of C# (event handler itself and reference to the VM) IMHO is far more predictable, legible and maintainable than screeds of 'clever' code.
[edit]
Just noticed the response below - which looks elegant but surely including a library in order to do something that can easily be done in .cs code behind is somewhat OTT also.
MVVM # - I did it My Way
___________________________________________
Man, you're a god. - walterhevedeich 26/05/2011
.\\axxx
(That's an 'M')
|
|
|
|
|
It seems the OP doesn't actually read anything that is linked to outside this site. I had linked to a complete working example above, and still the OP wanted someone to write his code.
|
|
|
|
|
You could use interaction triggers;
<Window x:Class="MainWindow"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:ei="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions">
...
<Button Name="DeleteButton" Content="Delete" Height="25" Width="60">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDown">
<ei:CallMethodAction MethodName="Delete" TargetObject="{Binding}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
...
In the ViewModel;
public class MainWindowViewModel
{
public void Delete()
{
}
}
"As beings of finite lifespan, our contributions to the sum of human knowledge is one of the greatest endeavors we can undertake and one of the defining characteristics of humanity itself"
|
|
|
|
|
Thanks Meshack Musundi, it worked.
|
|
|
|
|
Thanks Meshack Musundi, nice approach. Its working fine.
|
|
|
|
|
Hi,
Currently I am facing problem in List View that, when we re-size the GridViewColumnHeader to the leftmost(width =0),not able to enlarge that column.It's not accessible later.I want to do this functionality as same as DataGrid. In DataGrid, it wont allow user to resize the column to width zero.
How can we acheive this functionality in ListView?
Thanks
|
|
|
|
|
I guess, the best way to do this would be to use the retemplating technique described here[^].
|
|
|
|
|
Just an FYI to the OP (and POH), I implemented MinWidth and MaxWidth on my own custom ListView and while the guys over at SO say "it works", I can tell you from personal experience it is an incomplete solution . There are a lot of little nuances you have to handle that the posted solution does not.
Beyond just dragging the splitter around, there is also the splitter double-click column auto-size behavior that needs to be patched, dragging columns (re-ordering) around screws things up, and the one that took me quite a while to solve: in a specific usage scenario (I forget the exact details since it's been a while), but it was something like where if you had the columns big enough so you had a horizontal scroll bar, and then did the column resize / auto-resize so it shrunk down the columns to where the scroll bar went away, the ListViewItems would not be resized properly and the control rendering would get all messed up.
This feature was actually a real PITA to get working properly in all cases. It ended up being several HUNDRED lines of code.
|
|
|
|
|
Hi, please help me regards hiding and showing stackpannel from ViewModel.
|
|
|
|
|
The standard way to do this is to expose a boolean property from your ViewModel that indicates whether or not the items the StackPanel represents are visible or not (I have worded this carefully so that you don't get the idea that the boolean maps to the StackPanel in anyway). This property must raise the PropertyChanged event when it changes. Then, in your View, bind the StackPanel Visibility to this property; as you are aware, the Visibility property is not a boolean property, so you use the BooleanToVisibilityConverter[^] to convert between the boolean value and the Visibility of the object.
|
|
|
|
|
Can you please provide any code related to this
|
|
|
|
|
I have to assume you know how to add the code into your ViewModel, so it looks like the bit that you are confused about is what happens in the XAML. Well, in your user control, add the following into the UserControl.Resources section:
<BooleanToVisibilityConverter x:Key="booleanVisibilityConverter"> Then, in your StackPanel add this (assuming that your VM property is called ShouldShow)
<StackPanel Visibility="{Binding ShouldShow, Converter={StaticResource booleanVisibilityConverter}}"
|
|
|
|
|
If you are gonna do that, you might as well just expose a Visibility property from the VM and cut out the middle man. EDIT: unless that bool would be used for various things besides visibility I mean .
|
|
|
|
|
There's an implication there, though, that your testing code is going to bring in a reference to System.Windows for something that really isn't needed. The converter method keeps your VM test code 100% plain POCO with no WPF dependency.
|
|
|
|
|
But in reality the property shouldn't be called "ShouldShow" but "IsOverseasTransaction" (or whatever business rule the View is using to determine visibility.
MVVM # - I did it My Way
___________________________________________
Man, you're a god. - walterhevedeich 26/05/2011
.\\axxx
(That's an 'M')
|
|
|
|
|
Hi, I have just started working on MVVM, MVVM is new for me, this stackpanel visibility i have to show/hide on button command. Can you please provide any idea how to show/hide on button command from view model.
Thanks Pete O'Hanlon.
|
|
|
|