|
You could consider presenting your data in a ListBox or a ListView and set IsSyncronisedWithCurrentItem="True" using the autamatic Parent Child binding in WPF.
|
|
|
|
|
Is any way to do it with datagrid rather then with listbox, and is it possible to show me with some sample code according to my question please...
kind regards
lapeci
|
|
|
|
|
I don't know any quick way to do it with Grid, but you can get a very similar look by using a list view - maybe something along these lines: Other than that wait for some one else to come up with the answer. Or read up on Binding.
<ListView Name="lvwCommandLog"
ItemsSource="{Binding Path=CommandLog, Mode=TwoWay}"
MouseDoubleClick="lvwCommandLog_MouseDoubleClick"
ToolTip="Double click to run this command again" >
<ListView.View >
<GridView >
<GridViewColumn Header="Name" DisplayMemberBinding="{Binding Name, Mode=TwoWay}" ></GridViewColumn>
<GridViewColumn Header="Age" DisplayMemberBinding="{Binding Age}" ></GridViewColumn>
<GridViewColumn Header="Time" DisplayMemberBinding="{Binding Path=Time, StringFormat=\{0:h\\:mm\\:ss\}}"></GridViewColumn>
</GridView>
</ListView.View>
<ListView.ContextMenu>
<ContextMenu>
<MenuItem Header="Do Something" Click="MenuItem_Click" />
</ContextMenu>
</ListView.ContextMenu>
</ListView>
<Text Text="{Binding Name}"/>
|
|
|
|
|
There are two ways to do this:
1. Bind the DataGrid's SelectItem to a property in your ViewModel (or code behind if you're not using MVVM ), then in the setter for that property populate properties for the TextBoxes, ComboBoxes etc.
This method has the advantage of being able to add a Cancel button.
2. Bind the TextBoxes, ComboBoxes etc to the DataGrid's SelectedItem property. Something like this:
{Binding ElementName=DataGrid1, Path=SelectedItem.TextPropertyName}
This method saves you a bit of coding but doesn't offer an easy way to cancel changes.
|
|
|
|
|
I create a library of these classes contains a user control that contains images as background to some button, I add it to the main page such as referance, I added this code to retrieve the control xaml user
<Window x: Class = "WpfApplication3.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"
xmlns: usercontrol = "clr-namespace: usercontrol; assembly = usercontrol">
<Grid>
<usercontrol:myeditor> </ usercontrol: myeditor>
</ Grid>
</ Window>
but i get an exception: the user control Cannot locate resource 
|
|
|
|
|
What are the values of the 'Build Action' and 'Copy to Output' properties of the background image (right click - properties)?
What does the xaml (or code) look like for assigning the image as the background of the UserControl look like?
|
|
|
|
|
Your error is going to be in the myeditor usercontrol. Like Jeremy suggested check to ensure that your image sources on the control are correct, and that the control is able to locate them during runtime.
|
|
|
|
|
Hi guys,
I'm working for the first time in WPF with MVVM pattern and I have a datagrid that is populated according to search terms in textbox on top. Right now, I'm able to populate the grid with all the data but I'm not able to get the value of the TextBox so I can filter it.
So here's a bit of the code:
In ViewModel:
private string p_searchName;
public string _searchName
{
get
{
return p_searchName;
}
set
{
p_searchName = value;
base.RaisePropertyChanged("_searchName");
}
}
In xaml file
<TextBox Height="23" HorizontalAlignment="Left" Margin="2,45,0,0" Text="{Binding _searchName}"
Name="tb_SearchName" VerticalAlignment="Top" Width="99" FontFamily="Lucida Console" TabIndex="10"
Grid.Column="1" />
Any help is greatly appreciated!
Thanks
|
|
|
|
|
The binding looks right, but are there any errors in the output window when loading that form?
The other thing that it may be, is that the TextBox control doesn't update the ViewModel until it loses focus. Not sure about that though...
|
|
|
|
|
There are no errors in the output window. But you are quite right about the focus. I just added
UpdateSourceTrigger=PropertyChanged
like this
<TextBox Text="{Binding Name, UpdateSourceTrigger=PropertyChanged}"/>
and it actually works... But I really don't see why this is so.
Thanks for the help!
|
|
|
|
|
I assume the default for UpdateSourceTrigger is LostFocus, and it is set that way for performance reasons. Every time you call the setter, the setter raises the OnPropertyChanged event, WPF listens to that event and calls the getter.
|
|
|
|
|
Hmm.. thanks Jeremy!
|
|
|
|
|
Make your binding Mode="TwoWay" default is only one way so you see the data but are not telling the datacontext the data has changed
And yes the change is only notified when the user leaves the textbox
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Tried that too, didn't work unfortunately.
|
|
|
|
|
You need to set your UpdateSourceTrigger in your binding like this <TextBox Text="{Binding MyProperty, UpdateSourceTrigger=PropertyChanged}"/>
|
|
|
|
|
Yes you're right. Just did that a minute ago or so
By the way... do you know why this is so? Just curious!
|
|
|
|
|
The WPF textbox has a default UpdateSourceTrigger of LostFocus, which means that it only updates it's bound value when the user focuses on another control. By changing the trigger to update when the property changes, it updates it's bound value every time the user enters/deletes/changes a letter. Here is the MSDN page that discusses this How to: Control when the TextBox Text Updates the Source[^] .
Hope this helps
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
|
Great, Glad it helped
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
Every time I look at learning about DP's, I walk away confused.
Anyone know of any decent entry level tutorials?
Everything makes sense in someone's mind
|
|
|
|
|
This[^], IMO, is one of the best reads on Dependency Properties.
|
|
|
|
|
Thank you
Everything makes sense in someone's mind
|
|
|
|
|
Kevin Marois wrote: Every time I look at learning about DP's, I walk away confused.
Anyone know of any decent entry level tutorials?
What's confusing about them?
By now, I assume you are familiar with data binding? Well, as you know... in order for the WPF UI subsystem to know when to update a UI element, it needs to know when the data value has changed. It needs to be able to know that on ANY object, so there needs to be a standard mechanism.
In fact, there are two standard mechanisms.
1) INotifyPropertyChanged / INotifyCollectionChanged - this is how you implement your view models & business objects... typically you'll have your ViewModelBase / ObservableObject base classes and derive everything from them
2) Dependency Properties - Generally, you shouldn't really need to use them in user applications since mechanism #1 is favored for that and DPs are a relative PITA to implement (vs mech #1). They are just objects that are stored by the framework instead of in your object and automatically implement change notification. I generally like to use them in custom controls only.
The benefit of DPs is that you don't need to liter your code with OnPropertyChanged("Foo"); type code.
The downside of DPs is that you have to 1) register them (around 2 to 10 lines of code depending on what options you use) 2) implement getter & setter (just call GetValue / SetValue).
There is a Visual Studio macro that spits out the code, so no biggie.
If you want to hook into the change notification, you need to register a STATIC callback, redirect into your VM, etc.
Just a royal PITA.
Basically, you should only use DP's in controls.
EDIT: there are some features that require use of DPs such as animations.
|
|
|
|
|
Thank you for your excellent response.
Everything makes sense in someone's mind
|
|
|
|
|
Hello guys anyone has the code of how to move an image from one place to another using the mouse in silverlight ? I still want the image that has been moved to another beneath it so that it can also be moved up or reach a certain number.
thanks.
|
|
|
|