|
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.
|
|
|
|
|
I already have. All the pieces are there. You hook up a command - you set the boolean property and then you raise the PropertyChanged event. As long as you have this view model hooked up to your DataContext, and you use the XAML I showed, you should be good to go.
|
|
|
|
|
Thanks Pete O'Hanlon, its working perfectly.
|
|
|
|
|
Hi,
How to send the content of a button from view to ViewModel on click command.
|
|
|
|
|
DO you have some code you have tried?
|
|
|
|
|
Thanks for reply. No sorry i dont have any code right now, i have only button click command code.
can you give any solution.
|
|
|
|
|
You should try and code something up and then ask why it isnt working. We can tell you what your problems are, but youll have to do the work yourself, deal?
|
|
|
|
|
When you bind the command add a CommandParameter, this is picked up as an object in the VM method you bind to.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
yes its working, thanks Mycroft Holmes....
|
|
|
|
|
This sounds incorrect. Can you show some code?
You would want to pass the context of the view to the view model.
|
|
|
|
|
Abhinav, I got the solutions, thanks for showing interest.
you asked for code, so i am displaying here:
Text = {Binding Command} CommandParameter="{Binding ElementName=btn1, Path=Content}"
|
|
|
|
|
I am trying to show a chart control in my application where the chart value comes at runtime. To imitate that I tried adding a chart control and populate value on button click, but every time I try to do so error: "No suitable axis is available for plotting the dependent value"
My XAML looks like this:
<chartingToolkit:Chart Name="chart1" Height="603" VerticalAlignment="Top">
<chartingToolkit:Chart.Axes>
<chartingToolkit:LinearAxis Orientation="Y" Interval="" ></chartingToolkit:LinearAxis>
</chartingToolkit:Chart.Axes>
<chartingToolkit:LineSeries DependentValuePath="Value" IndependentValuePath="Key" ItemsSource="{Binding}" />
</chartingToolkit:Chart>
in code behind I have created following class to hold data:
public class ChartData
{
public ChartData(string key, double val)
{
Key = key;
Value = val;
}
public string Key;
public double Value;
}
Also I created an ObservableCollection of this class. Now on every button click I add certain data to this collection and at the load method of page I set the datacontext of chart to this observable collection.
I tried a lot but the error won't go.
Any help is appreciated.
Thanks in advace.
|
|
|
|
|
|
I am using WPFToolkit's chart control. However I figured out the issue. The class to which my collection was binded was having private properties istead of public. On changing this it's working fine.
Thanks for replying
|
|
|
|
|
hi,
is there a way to get the closed now !!!!!!, expression gallaery website content,
mirrors, archives, backup , .... anything !!
thanks and good day.. or night
|
|
|
|
|
Have you tried the links on the closure announcement[^]?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I am using Date and Time picker from windows phone toolkit. i have both controls on my page. I am using two way binding to the System.DateTime property in one of my class, both the controls i.e. the date picker and time picker are bound to one property. everything is working fine except a corner case (which is not really a corner case)
When i change the value in date picker, the property in my class is updated, which is good. When i change the time through time picker the Time is updated in my DateTime property. However while changing the time if i go past 00:00hrs (i.e. 'scroll' through hours until i go pass 0) the date value of the DateTime property is set to current date. This is something i want to avoid, Is there a way i can solve this problem ?
<toolkit:DatePicker Value="{Binding MyDateTime, Mode= TwoWay}"/>
<toolkit:TimePicker Value="{Binding MyDateTime, Mode= TwoWay}"/>
public DateTime MyDateTime
{
get { return dateTime; }
set { dateTime = value; }
}
|
|
|
|
|
Not likely, each one quite reasonably believes it has full authority to set the entire value for the bound property.
You'll have to bind to two properties and then combine the Date and Time parts into a single value for your later use.
|
|
|
|
|
yes, that seems to be the only solution. i have now used to properties and i am combining the date and time
|
|
|
|
|
I have a MaterialsViewModel. There are 7 different types of materials. I am defining the views->VM's in my resource file like this:
<DataTemplate DataType="{x:Type vm:MaterialsViewModel}">
<vw:MaterialsView/>
</DataTemplate>
In the VM I set an enum called 'MaterialType' based on the type of material.
How do I set up the resource file to select the right view?
Thanks
If it's not broken, fix it until it is
modified 17-Oct-13 16:15pm.
|
|
|
|