|
I just noticed that your class Customer actually implements INotifyPropertyChanged.
The alternative to this could be to allow your view model to implement it. Bind your xaml control to a property in the view model - a property that represents your customer entity. Using this, you should be able to get a notification to your view model.
|
|
|
|
|
Now you see, that was how I had things set up originally. The problem is (as I mentioned) with CanExecute functions being called for my various commands - the binding is successfuly updating the entity. If I implement INPC on the entity, then I know that a field has changed at that level, but there's no way to let the ViewModel know, and since that's where the CanExecute functions live, it's never getting called.
Going the other way, if I implement INPC on the VM, then it correctly calls CanExecute when the entity itself changes, but not when one of the fields changes...
C# has already designed away most of the tedium of C++.
|
|
|
|
|
Hi,
I am unable to select an item of a particular value of a combobox in wpf.
For example say i have a textbox, a button and a combobox. The combobox has 3 items with values as 1 , 2 , 3 and display text as a , b , c. On load of the window these values and text gets binded to the combobox. On load nothing is being selected i.e. the combobox is blank.
Now when i type 1 in the textbox and click the button i want to show the value 1 as selected i.e. on click of the button "a" should get displayed.
Can anyone please help. Thanks in advance.
Regards,
Samar
|
|
|
|
|
Are you using MVVM pattern?If so then bind the SelectedValue of combobox to a property in view model and while clicking button set that property in view model.
|
|
|
|
|
Hi arun,
No i am not using MVVM. I want to keep this simple but yes i do not want to do it in xaml. I can do it in xaml by using binding and elementname.
I want to do it in c# code. Is there anything in wpf which is similar to the following what we do in web?
DropDownList1.Items.FindByValue("1").Selected = true;
modified on Tuesday, April 13, 2010 5:32 AM
|
|
|
|
|
comboboxId.SelectedValue = yourvalue.
But instead add a property in the code behind, bind it to the selected value of combobox and while clicking button set that property.
|
|
|
|
|
Thanks a million Arun!!! This solved by problem. I had tried this earlier but somehow was not able to get through but now it is working. thx again..!!!
|
|
|
|
|
Happy to see that your problem solved.
|
|
|
|
|
Samar Can u try with the selectedItem .......
|
|
|
|
|
Hi sunil i tried with selecteditem but it is showing me null as there is nothing selected.
|
|
|
|
|
Ok can u loop throught the source that u have binded and get the excat object that satisfy u r requirement and make that object as the selected item .Beacuse the data binding concept is something different in WPF
|
|
|
|
|
I think selected item was again throwing me null or something. I do not remember correctly now. But i got thru with the problem as below. Thank you very much for your help.
omboboxId.SelectedValue = yourvalue;
|
|
|
|
|
I need to access a WPF object, Grid, in a class. But I am not able to do so, as it is inaccessible. I need to change the visibility of a Grid object (WPF_Grid) based on certain conditions/values of class.
My Main Code:
public partial class MainWindow : Window
{
public TempDataClass tDataClass;
public MainWindow()
{
this.InitializeComponent();
tDataClass = new TempDataClass();
}
private void SomeMainFunction()
{
if (SomeMainCondition1)
{
tDataClass.someClassFunction1();
}
else
{
tDataClass.someClassFunction2();
}
}
}
My Class Code:
public class TempDataClass : DependencyObject
{
public FolderFilingDataClass()
{
}
public void someClassFunction1()
{
if (SomeClassCondition1)
{
WPF_Grid.Visibility = Visibility.Hidden;
}
}
public void someClassFunction2()
{
if (SomeClassCondition2)
{
WPF_Grid.Visibility = Visibility.Visible;
}
}
}
One way around is passing objects as parameter, but is there any better way? I am sure, there is...
|
|
|
|
|
you can create a property in TempDataClass and set it before tDataClass.someClassFunction1();
|
|
|
|
|
Sorry! Not clear for me...
|
|
|
|
|
Passing the parameter and my posted solution having the same effect.
Create a property in your TemplateClass to hold the object and set this object from the main class where you are calling the method from.
|
|
|
|
|
Ok, Right! Got it
|
|
|
|
|
While the other answer you got will work correctly, it's not the WPF-ish way of doing it. Ideally you should bind the grid's Visibility to a public property on the data class where you also need to implement INotifyPropertyChanged. If this property is a bool, you'd also need to use a binding converter (to convert from bool to Visibility).
|
|
|
|
|
Thanks Nishant for you reply! Yes, I understand your point. This Grid and Visibility property was just a small example of my problem. Sometime I have a canvas and need to addChildren, removeChildren and many more thing from class. So, basically all drawing methods implemented inside class, while no objects accessible. In that case, i am really not sure how binding will work.
|
|
|
|
|
Ok, the name TempDataClass led me to believe that it was some kind of Model class. So it seems it's merely a UI helper class that dynamically manipulates your UI. In which case it's reasonable to just pass in the Grid instance to it and access it that way.
|
|
|
|
|
I am having trouble with a Datagrid within a stackpanel. I put a stackpanel around the datagrid because I want the datagrid size to collapse to accordingly to the amount of rows I bring back. My problem lies when I bring back a lot of rows because it displays everything in the datagrid and the datagrids scrollbar never shows. I know I could put a maxheight on the datagrid but if I need to take into account the actual size of the window because of screen resolution and size. If I put a maxheight on the datagrid it would not look right when the screen is maximized, there would be a lot of extra white space. I want the datagrid to expand proportionately to the bottom of the screen. I am using the MVVM pattern.
<Grid x:Name="PatientSearchResultsGrid" Grid.Row="2" Margin="0" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="1" Margin="0,12,0,46" >
<Grid Margin="0,3,4,23" Panel.ZIndex="596" x:Name="LayoutGrid" Visibility="{Binding HideShowDatagrid, Converter={StaticResource MyBooleanToVisibilityConverter}}" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<dg:DataGrid
Cursor="Hand"
Grid.Row="1"
AlternationCount="2"
SelectedItem="{Binding SelectedPerson}"
ItemsSource="{Binding SelectedPeople}"
Style="{DynamicResource DataGridStyle}"
AutoGenerateColumns="False"
x:Name="PatientSearchResultsDG"
Margin="2,-17.8,3,1.7" BorderThickness="1,0,1,1" BorderBrush="#FF202020" >
<dg:DataGrid.Resources>
<Style TargetType="{x:Type dg:DataGridRowHeader}">
<Setter Property="Background" Value="Transparent"/>
</Style>
</dg:DataGrid.Resources>
<dg:DataGrid.Columns>
<dg:DataGridTextColumn Binding="{Binding Name}" IsReadOnly="True" x:Name="PatientName" Width="*" Header="Name" />
<dg:DataGridTextColumn Binding="{Binding SidNumber}" IsReadOnly="True" x:Name="SID" Width="*" Header="SID" />
<dg:DataGridTextColumn Binding="{Binding InmateNumber}" IsReadOnly="True" x:Name="InmateNum" Width="*" Header="Inmate #" />
<dg:DataGridTextColumn Binding="{Binding Sex}" IsReadOnly="True" x:Name="Sex" Width="*" Header="Sex" />
<dg:DataGridTextColumn Binding="{Binding DateOfBirth, StringFormat=' \{0:MM/dd/yyyy\}'}" IsReadOnly="True" x:Name="DOB" Width="*" Header="Date of Birth" />
<dg:DataGridTextColumn Binding="{Binding FacilityName}" IsReadOnly="True" x:Name="Facility" Width="*" Header="Facility" />
<dg:DataGridTextColumn Binding="{Binding Housing}" IsReadOnly="True" x:Name="Housing" Width="*" Header="Housing" />
<dg:DataGridTextColumn Binding="{Binding Active}" IsReadOnly="True" x:Name="Active" Width="*" Header="Active" />
<dg:DataGridTextColumn Binding="{Binding Locked}" IsReadOnly="True" x:Name="Locked" Width="*" Header="Locked" />
</dg:DataGrid.Columns>
</dg:DataGrid>
</Grid>
</StackPanel>
</Grid>
|
|
|
|
|
Member 4540564 wrote: <grid.rowdefinitions>
<rowdefinition height="Auto">
Change the Height to * and then try again.
|
|
|
|
|
I was having the same problem and solved it by replacing the StackPanel with a Grid. It looks as though the StackPanel does not constrain the height of its children while the Grid does.
|
|
|
|
|
Hi
I am trying to change node indent for treeview control in wpf, but found that it has no NodeIndent property in wpf.
Does anyone who knows how to change the node indent?
jesse
|
|
|
|
|