|
Ok, what I'm asking is HOW? What's the syntax? What does the code in the VM look like?
If it's not broken, fix it until it is
|
|
|
|
|
Let's assume you have a Model that looks like this:
public class MyModel : PropertyChangeBase
{
private string _name;
public string Name
{
get { return _name; }
set
{
if (_name == value) return;
_name = value;
RaisePropertyChanged("Name");
}
}
} Then, there's this VM:
public class MyViewModel : PropertyChanged
{
private MyModel _model;
public string Name
{
get { return _model.Name; }
set
{
if (_model.Name == value) return;
_model.Name = value;
RaisePropertyChanged("Name");
}
}
} Then, your view simply binds to the Name property on your model. It's nothing complicated.
|
|
|
|
|
Ugh, I hate when people do this .
Just subscribe to _model.OnPropertyChanged += ...; and check for the properties you are interested in.
Only time you want to write a new getter / setter IMO is when the original property doesn't support INPC or you need INPC to behave in a different way for said property.
|
|
|
|
|
SledgeHammer01 wrote: Only time you want to write a new getter / setter IMO is when the original property doesn't support INPC or you need INPC to behave in a different way for said property.
Indeed, and as he wants to do something a different way for said property, this is the simplest solution, especially as it doesn't involve managing the lifetime of a none weak event subscription just to stick to an idealistic view.
|
|
|
|
|
I tried it the way SledgeHammer suggested, on the SelectedRecord (bound to the SelectedItem in the DG) I had a -= before the change to remove existing bindings and a += after the change, worked Ok.
Haven't tried POHs method but I would have no compunction shattering the MVVM design if it suited my needs .
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
How to create multi focus in Surface application so multiple users can use application togather on sur 40?
Multiple keyboards for all users, and each user can use own virtual keyboard?
|
|
|
|
|
have used a RadTileView,
<usercontrol
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
="" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns ="http://schemas.microsoft.com/expression/blend/2008" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" x:class="DemoShow.usercontrol.UserControl1" mc:ignorable="d">
<usercontrol.resources>
<Style.Triggers>
<Trigger Property="IsEnabled" Value="true">
<Setter Property="BorderThickness" Value="1,1,1,1" />
</trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="BorderThickness" Value="0,0,0,0"/>
</trigger>
</style.Triggers>
<datatemplate x:key="headerTemplate">
<textblock text="{Binding Number}">
<datatemplate x:key="contentTemplate">
<grid margin="5">
<grid.rowdefinitions>
<rowdefinition height="Auto">
<rowdefinition height="Auto">
<rowdefinition height="Auto">
<rowdefinition height="Auto">
<rowdefinition height="Auto">
<rowdefinition height="Auto">
<rowdefinition height="Auto">
<textbox grid.row="0" style="{StaticResource TextBoxThumb}" isenabled="{Binding Path=ShowFlag,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" text="{Binding Name,Mode=TwoWay}">
<textbox grid.row="1" style="{StaticResource TextBoxThumb}" isenabled="{Binding Path=ShowFlag,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" text="{Binding Birthday,Mode=TwoWay}">
<textbox grid.row="2" style="{StaticResource TextBoxThumb}" isenabled="{Binding Path=ShowFlag,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" text="{Binding age,Mode=TwoWay}">
<textbox grid.row="3" style="{StaticResource TextBoxThumb}" isenabled="{Binding Path=ShowFlag,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" text="{Binding Sex,Mode=TwoWay}">
<textbox grid.row="4" style="{StaticResource TextBoxThumb}" isenabled="{Binding Path=ShowFlag,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" text="{Binding CheckType,Mode=TwoWay}">
<textbox grid.row="5" style="{StaticResource TextBoxThumb}" isenabled="{Binding Path=ShowFlag,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" text="{Binding Time,Mode=TwoWay}">
<i:interaction.triggers>
<i:eventtrigger eventname="Click">
<i:invokecommandaction command="{Binding DataContext.LoginCommand,RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type UserControl}, AncestorLevel=1}}"
="" commandparameter="{Binding Name}">
<grid>
<telerik:radtileview
="" isautoscrollingenabled="True" isdockingenabled="True" isvirtualizing="True" columnscount="2" rowheight="200" columnwidth="300" minimizedcolumnwidth="300" minimizedrowheight="200" minimizeditemsposition="Bottom" contenttemplate="{StaticResource contentTemplate}" itemssource="{Binding Path=Items,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" itemtemplate="{StaticResource headerTemplate}" preservepositionwhenmaximized="False" tilestatechangetrigger="SingleClick">
i change the BindingList<people>
public class MainViewModel : ViewModelBase
{
private BindingList<people> items;
private BindingList<people> itemstem;
public ICommand LoginCommand
{
get
{
return new RelayCommand<object>(
(parameter) =>
{
ChangeInputEnable(parameter);
}
);
}
}
ui not update public class People
{
public string Name { get; set; }
public string Birthday { get; set;}
public string age { get; set; }
public string Sex { get; set; }
public string CheckType { get; set; }
public string Time { get; set; }
public string Number { get; set; }
public bool ShowFlag { get; set; }
}
private void ChangeInputEnable(object parameter)
{
//string str = parameter.ToString();
//var obj = items.FirstOrDefault(x => x.Name == str);
//int n = items.IndexOf(obj);
//MessageBox.Show(items[n].ShowFlag.ToString());
//if (obj != null)
//{
// if (obj.ShowFlag) obj.ShowFlag = false;
// else obj.ShowFlag = true;
// RaisePropertyChanged("ShowFlag");
// RaisePropertyChanged("Items");
// MessageBox.Show(items[n].ShowFlag.ToString());
// MessageBox.Show(str);
//}
string str = parameter.ToString();
var obj = items.FirstOrDefault(x => x.Name == str);
int n = items.IndexOf(obj);
if (obj != null)
{
if (obj.ShowFlag) obj.ShowFlag = false;
else obj.ShowFlag = true;
obj.Name += "tttt";
items.ListChanged += (o, e) => RaisePropertyChanged(("Items"));
itemstem = items;
items = null;
items = itemstem;
RaisePropertyChanged("Name");
RaisePropertyChanged("Items");
}
//items.Add(new People()
//{
// Birthday = "1985-08-08",
// age = "38",
// Sex = "Male",
// CheckType = "PET-CT",
// Time = "10:30",
// Name = "tttt",
// Number = "10"
//});
//RaisePropertyChanged("Items");
}
public MainViewModel()
{
List<people> itemsSource = new List<people>();
for (int i = 0; i < 5; i++)
{
itemsSource.Add(new People()
{
Birthday = "1985-08-08",
age = "38",
Sex = "Male",
CheckType = "PET-CT",
Time = "10:30",
Name = this.names[i % 12],
Number = i.ToString(),
ShowFlag =true
});
}
this.items = new BindingList<people>(itemsSource);
}
public BindingList<people> Items
{
get
{
return this.items;
}
set
{
this.items =value;
RaisePropertyChanged("Items");
}
}
private List<string> names = new List<string>
{
"Andrew Fuller",
"Martin Sommer",
"Anne Dogsworth",
"Steven Buchanan",
"Janet Leverling",
"Michael Suyama",
"Margaret Peacock",
"Robert King",
"John Steel",
"Laura Gallahan",
"Nancy Davolio",
"Ann Devon"
};
}
can you help me ?
|
|
|
|
|
lijizhe wrote: can you help me ? Not until you format your code properly, and add a detailed explanation of your problem.
Veni, vidi, abiit domum
|
|
|
|
|
i have a radscheduler in my wpf application i want to create apointment from another window programatically i have tried iappointment but it shows there is no resources, how can i set a resource for iappointment for radscheduleview.
|
|
|
|
|
I reckon the answer is in here[^].
|
|
|
|
|
I'm working on a WFP/MVVM app that hast portions that need to run on a Windows 8 tablet.
Some parts of the app are not responding to touch. Buttons do, but grid row selection and other controls do not.
I'm brand new to working with touch. My understanding is that if you don't handle the touch event, it's promoted to a click.
I can trap Touch Down/Up in the code behind. But that doesn't help with my Grid.SelectedItem in an MVVM environment.
Anyone have any experience here that can point me in the right direction?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
Did you use ManipulationStarted & ManipulationCompleted event?. Try this once.
|
|
|
|
|
How do you create a data grid in WPF with multiple bands? I can't find a single example
If it's not broken, fix it until it is
|
|
|
|
|
|
Wonderful.
I'll use 2 grids.
If it's not broken, fix it until it is
|
|
|
|
|
A number of third party tools like Telerik, Infragisitcs provide nested grid s that you could explore for your implementation.
|
|
|
|
|
Hello,
I have the next view XAML file:
<Grid>
<ScrollViewer>
<ItemsControl ItemsSource="{Binding MemControls}"/>
</ScrollViewer>
</Grid>
The ItemsControl binded to:
public ObservableCollection<UserControl> MemControls
{
get { return _memControls; }
set { _memControls = value; }
}
in the view Model.
I want to give the user an option to save GUI configuration. So when he press "Save" button i want to serialize the:
public ObservableCollection<UserControl> MemControls
<pre>
to XML file and when he want to restore GUI configuration i want to to desirialize from an XML file the list of controls and that way to restore GUI configuration.
How can i do it?
Maybe there is some other better way that dont involve XML files?
Thanks
|
|
|
|
|
Although this article [^]is for winforms it may give you some ideas.
I would also check out the comment from Tom Clement and see if he did an article on FormEx.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
|
Hello Listeners,
I created a SL application (using C#) that returns contents of a table in SQL database. Table has 5 columns (FirstName, LastName, Age..etc).
--A grid is populated with following:
EclipseMTXDomainContext context = new EclipseMTXDomainContext();
dataGrid1.ItemsSource = context.DBTables;
context.Load(context.GetDBTablesQuery());
--Mine domain service has an entry as follows:
public IQueryable<dbtable> GetDBTablesCompare() {
return this.ObjectContext.DBTables;
}
This works fine but
What I am trying to do now is load only two columns at a time so I added this in the domain services
public IQueryable<dbtable> GetTwoColms(string db1,string db2) {
return this.ObjectContext.DBTables.Where(P => P.col1Name == cl1 && P.col2Name == cl2);
}
--And the main program, added this to a button action
EclipseMTXDomainContext context = new EclipseMTXDomainContext();
dataGrid1.ItemsSource = context.DBTables;
context.Load(context. GetTwoColms Query("LastNames","FirstName"));
It does not fail but it does not return anything either.
Any help is greatly appreciated
|
|
|
|
|
My first guess:
You have the column names as "LastNames" (plural) and "FirstName" (singular) which looks suspiciously like a typo.
|
|
|
|
|
ThanX Matt,
that is not the issue, it is just careless type when creating the post.
|
|
|
|
|
picasso2 wrote: it is just careless type when creating the post. Then use Copy & Paste, so what we see here matches exactly with what you have in your program.
Veni, vidi, abiit domum
|
|
|
|
|
u can use lamda method select() return a implicit class consists of u wanted 2 columns
|
|
|
|
|
Hi all
below is my wpf progress bar
Dim duration As New Duration(TimeSpan.FromSeconds(20))
Dim doubleanimation As New DoubleAnimation(200.0, duration)
PBar.BeginAnimation(ProgressBar.ValueProperty, doubleanimation)
Now please tell me how to open a window after the progress bar load complete..
|
|
|
|