 |

|
Dang it...
|
|
|
|

|
Hard to say from that - we only have half the picture here. Tell you what, what do you see if you change the DataGridTemplateColumns into DataGridTextColumns? What appears in the text? Is the source correct then?
|
|
|
|

|
That did it. Thanks Pete
If it's not broken, fix it until it is
|
|
|
|
|

|
made stackedbarseries in silverlight to show "projects gantt chart"
now I wanna change the numbers shown in the Axes-X for example we have Worker John:
pr1: 201105 - 201115
pr2: 201120 - 201144
pr3: 201142 - 201207
etc...
so I made 2 series that the first seria is with tranceparent color then I make function that change the WW to range from 201101 (dont need before..) so the chart looks like:
pr1: 5-15
pr2: 20-44
pr3: 42-60 (53+7 or 52+7 depends on year)
now how can I change the Axes display to the original?
the code in xaml is:
<toolkit:Chart Name="ProjectChart" Title="Projects" Visibility="Visible" >
<toolkit:Chart.Series>
<toolkit:StackedBarSeries FontWeight="Bold" MouseLeftButtonUp="StackedBarSeries_MouseLeftButtonUp" MouseEnter="StackedBarSeries_MouseEnter">
<toolkit:SeriesDefinition ItemsSource="{Binding}" Visibility="Collapsed" Title="" Name="serEmpty"
DependentValueBinding="{Binding tranceparent_ser}"
IndependentValueBinding="{Binding projectName}"
>
<toolkit:SeriesDefinition.DataPointStyle>
<Style TargetType="toolkit:BarDataPoint">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0"/>
</Style>
</toolkit:SeriesDefinition.DataPointStyle>
</toolkit:SeriesDefinition>
<toolkit:SeriesDefinition ItemsSource="{Binding}" Title="Project" Name="serProjects"
DependentValueBinding="{Binding project_ser}"
IndependentValueBinding="{Binding projectName}">
<toolkit:SeriesDefinition.DataPointStyle>
<Style TargetType="toolkit:BarDataPoint">
<Setter Property="Background" Value="Blue"/>
<Setter Property="BorderBrush" Value="Blue"/>
<Setter Property="BorderThickness" Value="1"/>
</Style>
</toolkit:SeriesDefinition.DataPointStyle>
</toolkit:SeriesDefinition>
</toolkit:StackedBarSeries>
</toolkit:Chart.Series>
</toolkit:Chart>
thanks
|
|
|
|

|
I have an XML file structured this way:
<Emulators>
<Settings>
<vol name="10"/>
<Volume>10</Volume>
<Keys name="key1" value="1" />
<Keys name="key2" value="2" />
<Keys name="key3" value="3" />
<Keys name="key4" value="4" />
</Settings>
<System>
<Name>name1</Name>
<Icon>name1.png</Icon>
<topplayed>
<Top>top1</Top>
<Top>top2</Top>
<Top>top3</Top>
</topplayed>
</System>
<System>
<Name>name2</Name>
<Icon>name2.png</Icon>
<topplayed>
<Top>top4</Top>
<Top>top5</Top>
<Top>top6</Top>
</topplayed>
</System>
</Emulators>
I get no difficulties binding to tag, as well as tags contained into it.
I get no difficulties to bind the tag into a list box.....but I don't know how to bind to tags into .
How to populate a listbox with all elements of the currently selected ?
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication1"
Title="MainWindow" Height="721" Width="525" Background="#FF4E4E64">
<Grid Name="Grid1">
<Grid.DataContext>
<XmlDataProvider x:Name="SystemData" Source="C:\Users\Portable\Desktop\taper\WpfApplication1\Resources\Systems2.xml" XPath="Emulators" />
</Grid.DataContext>
<Grid.Resources>
<DataTemplate x:Key="Resource1">
<Label Content="{Binding XPath=@name}"/>
</DataTemplate>
<DataTemplate x:Key="Resource2">
<Label Content="{Binding XPath=@value}"/>
</DataTemplate>
<DataTemplate x:Key="Resource3">
<Label Content="{Binding XPath=Name}"/>
</DataTemplate>
<DataTemplate x:Key="Resource4">
<Label Content="{Binding XPath=Top}"/>
</DataTemplate>
</Grid.Resources>
<TextBox Text="{Binding XPath=Settings/Volume}" Height="30" HorizontalAlignment="Left" Margin="12,12,0,0" Name="TextBox5" VerticalAlignment="Top" Width="196" />
<ListBox ItemsSource="{Binding XPath=Settings/Keys}" ItemTemplate="{StaticResource Resource1}" IsSynchronizedWithCurrentItem="True" Height="92" HorizontalAlignment="Left" Margin="12,48,0,0" Name="ListBox1" VerticalAlignment="Top" Width="196" />
<ListBox ItemsSource="{Binding XPath=Settings/Keys}" ItemTemplate="{StaticResource Resource2}" Height="92" HorizontalAlignment="Left" IsSynchronizedWithCurrentItem="True" Margin="214,48,0,0" Name="ListBox2" VerticalAlignment="Top" Width="196" />
<ListBox ItemsSource="{Binding XPath=System}" ItemTemplate="{StaticResource Resource3}" IsSynchronizedWithCurrentItem="True" Height="104" HorizontalAlignment="Left" Margin="12,185,0,0" Name="ListBox3" VerticalAlignment="Top" Width="196" />
<ListBox ItemsSource="{Binding XPath=System/topplayed}" ItemTemplate="{StaticResource Resource4}" Height="74" HorizontalAlignment="Left" Margin="12,295,0,0" Name="ListBox4" VerticalAlignment="Top" Width="196" />
</Grid>
</Window>
Thank you very much!!
|
|
|
|

|
Hi All, I need to play streaming videos like Live TV News and live Cricket etc. in my WPF Application. I used Media Element But it did not worked out. If anyone has done that in any way please help me out.
|
|
|
|

|
Take a look at the sticky at the top on how to ask a question, yours was not a good example and will not get the answer you want. Try reading some of the articles, work through the samples[^] there are plenty out there.
Never underestimate the power of human stupidity
RAH
|
|
|
|

|
So I have this XAML code:
<Window.Resources>
<local:MainViewModel x:Key="ViewModel" />
</Window.Resources>
And this is the XAML for the actual control:
<StackPanel Orientation="Horizontal" Width="897" Margin="5" DataContext="{StaticResource ViewModel}">
<ItemsControl Width="897" ItemsSource="{Binding Intersections}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<WrapPanel Width="897" >
<RadioButton GroupName="Intersections"
Content="{Binding Text}"
IsChecked="{Binding IsChecked, Mode=TwoWay}" Width="150"/>
</WrapPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
In the code behind I have this public class:
Public Class MainViewModel
Sub New()
Intersections.Add(New Insertion() With {.Text = "Item 1"})
Intersections.Add(New Insertion() With {.Text = "Item 2", .IsChecked = True})
Intersections.Add(New Insertion() With {.Text = "Item 3"})
Intersections.Add(New Insertion() With {.Text = "Item 4"})
End Sub
Private _Intersections As New ObjectModel.ObservableCollection(Of Insertion)
Public Property Intersections() As ObjectModel.ObservableCollection(Of Insertion)
Get
Return _Intersections
End Get
Set(ByVal value As ObjectModel.ObservableCollection(Of Insertion))
_Intersections = value
End Set
End Property
Public Class Insertion
Private _Text As String
Public Property Text() As String
Get
Return _Text
End Get
Set(ByVal value As String)
_Text = value
End Set
End Property
Private _IsChecked As Boolean
Public Property IsChecked() As Boolean
Get
Return _IsChecked
End Get
Set(ByVal value As Boolean)
_IsChecked = value
End Set
End Property
End Class
End Class
The problem Im haveing is to get the RadioButtons to be shown Horizantaly, and I cant figure out how to do that. I have tried to set IsItemsHost="True" but Its giving me the error "A panel with IsItemsHost="true" is not nested in an ItemsControl. Panel must be nested in ItemsControl to get and show items.". Either I heave tried to do this in all the wrong places or Im missing some key information here.
To be clear the code works, but its giving me a stack of the RadioButtons, but I want the side by side like a WrapPanel.
The example is taken from here here[^], and I converted it to VB from C#.
modified 17 Sep '12 - 13:49.
|
|
|
|

|
Use ItemsPanelTemplate and put the radio buttons horizontally inside a stack panel.
E.g.
<ItemsControl.ItemTemplate>
<ItemsPanelTemplate>
<StackPanel Orientation='Horizontal' "/>
</ItemsPanelTemplate>
|
|
|
|

|
I tried this:
<StackPanel Orientation="Horizontal" Width="897" Margin="5" DataContext="{StaticResource ViewModel}">
<ItemsControl Width="897" ItemsSource="{Binding Intersections}">
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal">
<RadioButton GroupName="Intersections"
Content="{Binding Text}"
IsChecked="{Binding IsChecked, Mode=TwoWay}" Width="150"/>
</StackPanel>
</ItemsPanelTemplate>
</ItemsControl>
</StackPanel>
But this time it wont build properly with ItemsPanelTemplate, I have seen this on the webbefore also, but couldnt get it to work, Can you?
|
|
|
|

|
I think (though Im not sure), one needs to put the tag somewhere.
|
|
|
|

|
ITs working now, but its a strange code, and its well over a page long, so I dont think I'll be pasting it here, unless you are really interested
|
|
|
|

|
Ok Found the answer here[^] . The code that works looked like this:
<StackPanel Orientation="Horizontal" Width="897" Margin="5" DataContext="{StaticResource ViewModel}">
<ItemsControl Width="897" ItemsSource="{Binding Intersections}">
<ItemsControl.Template>
<ControlTemplate>
<WrapPanel Width="{TemplateBinding Width}" Height="{TemplateBinding Height}"
FlowDirection="LeftToRight" IsItemsHost="true">
</WrapPanel>
</ControlTemplate>
</ItemsControl.Template>
<ItemsControl.ItemTemplate>
<DataTemplate>
<WrapPanel Width="120">
<RadioButton GroupName="Intersections" Content="{Binding Text}" IsChecked="{Binding IsChecked, Mode=TwoWay}" Width="150"/>
</WrapPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
|
|
|
|

|
I have this combobox:
<ComboBox x:Name="cboServerList"
Grid.Row="0"
Grid.Column="1"
Margin="5"
Height="23"
IsEditable="True"
ItemsSource="{Binding Servers}"
SelectedItem="{Binding SelectedServer}"
TextSearch.TextPath="ServerName"
Text="{Binding ServerName}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding ServerName}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
Since it's editable, as soon as I start typing the SelectedServer property's setter fires. How can I set it up so that it doesn't fire until the user presses Enter or tabs out?
Thanks
If it's not broken, fix it until it is
|
|
|
|

|
Set the UpdateSourceTrigger of the binding to LostFocus. That won't handle the enter key though. Which is probably ok since the enter key has a different meaning. Dunno why you'd want to do this though. Sounds like an issue with your VM setter being too expensive??
|
|
|
|

|
Thanks for the tip
SledgeHammer01 wrote: Dunno why you'd want to do this though. Sounds like an issue with your VM
setter being too expensive??
Why would you want the property's get to fire on each keystroke?
If it's not broken, fix it until it is
|
|
|
|

|
Kevin Marois wrote: Why would you want the property's get to fire on each keystroke?
Who cares if you update a string 50 times? What do you think happens with WPF controls? If you scroll down a combo box, you'll get a bunch of updates for each item too.
If you are binding to expensive setters, your design is wrong. In your example, it is perfectly fine to update a string property 50 times, but if that is also triggering 50 database updates, then thats an improper design.
You are trying to solve the wrong problem here I think .
|
|
|
|

|
SledgeHammer01 wrote: Who cares if you update a string 50 times?
I care. This is a search field. I don't want the search running after every keystroke. Of course it's bound to a property. How else would you do it?
SledgeHammer01 wrote: If you are binding to expensive setters, your design is wrong. In your example,
it is perfectly fine to update a string property 50 times, but if that is also
triggering 50 database updates, then thats an improper design
This is exactly what I'm trying to avoid. That's why I don't want the setter to execute until the user presses enter. That's a pretty normal requirement.
If it's not broken, fix it until it is
|
|
|
|

|
Ok... I'm confused. There are two ways to do search:
1) a real-time live search (i.e. Google, Internet Explorer, etc)
2) only do the search when the user clicks the OK / search button
For #1, you would do it on every key stroke.
For #2, it depends on how your UI is laid out. Do you have a pop up dialog with an OK button? Or is it something like where you have an edit box in the main window frame?
Irregardless of how you are implementing #2 UI wise, I think you are confusing your property setter with your action trigger. Those should be separate. The "public string SearchText" property should not kick off a search. Since all you should be doing in it is updating the property, its fine to update it 50 times. Then your enter key / ok / search button will send a command to the VM to kick off the search.
The button sending the command portion I'm assuming you already know how to do, for trapping the enter key, all you need to do is use your EventToCommand mapper to map the KeyDown event of the edit box to an ICommand and forward along the eventArgs. In your command handler function, you would simply check if the key pressed was the enter key. All nice and MVVM'y .
|
|
|
|

|
SledgeHammer01 wrote: Ok... I'm confused. There are two ways to do search: 1) a real-time
live search (i.e. Google, Internet Explorer, etc) 2) only do the search when
the user clicks the OK / search button
Ok, well that's just your opinion. I can point out mroe than a few UI designs where search happens when the user types, and also where nothing happens until you press enter. Open up Windows Explorer and type something into the search field. Nothing happens until you press enter. There's no button, becuase it's an extra step. Type, then reach for the mouse. Bad design IMHO. For heads down work, press enter to confim/trigger and action.
At any rate, I'll set the UpdateSourceTrigger of the binding to LostFocus.
If it's not broken, fix it until it is
|
|
|
|

|
Lol... you just described #1 and #2. #2 is trigger based, I thought it was implied that the trigger could be ANYTHING whether it be a button, the enter key, or you stepping on your cats tail. Silly me.
At any rate, I'll let others help you from now on, as you are kind of rude to people who help you for free on thier own time .
|
|
|
|

|
SledgeHammer01 wrote: At any rate, I'll let others help you from now on, as you are kind of rude to
people who help you for free on thier own time .
Wow, sorry. I didn't mean to be rude. Sorry if I came across that way.
If it's not broken, fix it until it is
|
|
|
|

|
I have previous experience using WinForms and the DataGridView control. I am trying to re-code a previous program using WPF that reads a parts list from a delimited text file and displays results in a DataGrid control.
In WinForms, I was able to assign a tag to the DataGrid row that I used to link individual URLs to our company's HTML-based inventory program. However, I am unsure how to do this (if it's even possible) in WPF. Currently, I read from the text file and load its contents into a List. From there, I filter the List by whatever the user selects, then display the results in a DataGrid control. I want to open up the browser when the user selects a row, but can't figure out how to bind the URL to the row. Is this possible? If so, can someone help point me in the right direction?
Thanks.
|
|
|
|

|
As long as you use data binding to bind your data to the grid, you really don't have much of a problem. Each row will be bound to the original item in the list, so it's simply a matter of reading from your SelectedItem, which will return the real item you are bound to.
|
|
|
|

|
Hi Pete,
Thanks for the response! I am not sure what you are suggesting. I am binding the data from the List into separate columns in my DataGrid. But instead of returning the information in the DataGrid, I want to open a browser window and go to the URL.
It's hard to explain without pictures, but I have a DataGrid with 6 columns. Under column 1, I list a description, with a hyperlink look. I bind the description of the part to that column. When the user clicks on that row, that's when I want to open the browser window. I thought about just using a DataGridHypertextColumn, but every example I could find online used an absolute address (http://exampleaddress.com). I will need to read the address from a textfile database. I suppose I could add another column and bind the URL to its own DataGrid column, but I am trying to avoid that.
Since I can't upload pictures, I have included the code.
private List<addData> LoadCollectionData()
{
List<addData> readData = new List<addData>();
string searchLine = (machineComboBox.SelectedValue.ToString()).ToUpper();
string findLine = searchTextBox.Text.ToUpper();
foreach (string readLine in File.ReadAllLines(path))
{
if (readLine.Contains(searchLine) && readLine.Contains(findLine))
{
string[] myData = readLine.Split('|');
readData.Add(new addData()
{
description = myData[0],
ICN = myData[1],
RIN = myData[2],
indexCode = myData[3],
location = myData[4],
machine = myData[5]
});
webLink = myData[6];
}
}
return readData;
}
And here is the XML:
<DataGridTextColumn Header="Part Name" CanUserResize="True" Width="225" Binding="{Binding description}">
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="FontSize" Value="20"/>
<Setter Property="FontWeight" Value="Black"/>
<Setter Property="TextElement.Foreground" Value="Blue"/>
<Setter Property="TextDecorations" Value="Underline"/>
<Setter Property="TextWrapping" Value="Wrap"/>
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="Cursor" Value="Hand"/>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
I apologize for being a little slow in understanding what you have explained so far, but I am very new to WPF and DataGrid seems much more complicated than it was in WinForms.
|
|
|
|

|
Ok, you're missing a bit out here. How do you bind the data to the DataGrid itself? I'd expect to see something like ItemsSource="{Binding MachineInfo}" in the DataGrid definition (replace MachineInfo with whatever collection your data is really in - it should be a public property on the class that you have bound to the view as the DataContext).
I appreciatet these terms may be confusing, but it's a little tricky explaining all of them in a forum post - they are covered more by articles. Let me know if you have any problems with this.
|
|
|
|

|
Hi again Pete,
Sorry it took me so long to respond. I'm actually an Electronics Tech on an oil rig so I got a little busy last night.
My binding was not in the code I provided (sorry!). It was actually in the code-behind, binding to a List collection via a method, so it looked something like this:
partsDataGrid.ItemsSource = LoadCollectionData();
And the method:
private List<addData> LoadCollectionData()
{
List<addData> readData = new List<addData>();
string searchLine = (machineComboBox.SelectedValue.ToString()).ToUpper();
string findLine = searchTextBox.Text.ToUpper();
foreach (string readLine in File.ReadAllLines(path))
{
if (readLine.Contains(searchLine) && readLine.Contains(findLine))
{
string[] myData = readLine.Split('|');
readData.Add(new addData()
{
description = myData[0],
ICN = myData[1],
RIN = myData[2],
indexCode = myData[3],
location = myData[4],
machine = myData[5],
webLink = myData[6]
});
}
}
return readData;
}
From there, I binded the elements of the List to each column of the DataGrid.
I did find a solution to my problem, and it was in the misunderstanding of how a DataGrid actually works (along with how to access a List collection). My bindings were correct for the DataGrid, however, in essence, I wanted to bind two separate pieces of information to one column. As far as I can tell from researching, that is not allowed. And I'm not sure that would be considered good programming if it were.
The solution to my problem was to access the 'webLink' variable in the List separately, and then recall the URL associated with it when I selected the row. The code I used looks something like:
private void partsDataGrid_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
{
int index = partsDataGrid.SelectedIndex;
if (index < 0)
index = 0;
else
{
string webAddress = ((addData)partsDataGrid.Items[index]).webLink;
}
}
As always, I am grateful for your help and appreciate the fact that more experienced programmers are willing to help others who are not quite as smart as they are...yet!
Thank you for the guidance.
|
|
|
|

|
This is probably an unusual question as I cannot find anything that makes me think that what I want to do is common practice but not doing this causes a memory leak.
The reason for registering a scriptable object is to be able to use the unbeforeunload method (JavaScript) at application exit. This is only needed at a very specific and brief time during the application lifetime after which I would like to cancel the registration of the scriptable object as it only causes to keep the page (this instance) alive in memory for the rest of the app lifetime. Unregistering (removing the key) and re-registering when it is needed again would solve the problem. I just don't know how to do it.
Here is the code :
<pre>Application app = Application.Current;
if (!app.IsRunningOutOfBrowser)
{
HtmlPage.RegisterScriptableObject("Page", this);
}
[ScriptableMemberAttribute]
public string LeaveRequested()
{
//method run before unload
}
[ScriptableMemberAttribute]
public bool PreventLeave()
{
return (bool)PreventLeaveCheckBox.IsChecked;
}</pre>
This works like a dream when it's needed, but it's a nuisance when it's not required.
Thanks for any help in advance.
|
|
|
|

|
You are really posting in the wrong place. People here do not do much with HTML. You need to post on an ASP.NET forum.
|
|
|
|

|
I am using this in a Silverlight 5 project ! So definitely in it's place.
|
|
|
|

|
Yes I see the out of browser reference now.
Basically a WPF developer, so not much help here.
|
|
|
|

|
I apologise if this is on not the correct location to post this issue.
I am making a SOAP call to client web service setup via WCF. It is third party code we are trying to integrate with our application. It keep coming back with CommunicationException: Error in deserializing body of reply message for operati
on and
communicationException System.InvalidOperationException: There is an error in XM
L document (3, 432). ---> System.Xml.XmlException: The maximum nametable charact
er count quota (16384) has been exceeded while reading XML data. The nametable i
s a data structure used to store strings encountered during XML processing - lon
g XML documents with non-repeating element names, attribute names and attribute
values may trigger this quota. This quota may be increased by changing the MaxNa
meTableCharCount property on the XmlDictionaryReaderQuotas object used when crea
ting the XML reader.
I tried searching the web, tried a few things mentioned like changed the C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\vsdiag_regwcf.exe.config. nothing worked. if anyone has ideas,thanks for your time.
|
|
|
|

|
Hello All, I am stuck in Wpf datgrid Cell updation. I want the backcolor of a cell change when the value in the cell increases or decreases accordingly. like if the value increases the cell backcolor shud become green, and when the value decreases then its backcolor is red. Also when can get the increment or decrement value or the previous value so that i can know by how much it has decreased or increased. Thanks
|
|
|
|

|
I'm going to assume that you are using MVVM here, and I'm going to show you how to do this without needing to use a Value converter. Some may argue that this isn't pure MVVM because I'm going to put a colour in the VM, but it's not one that I would really worry about too much. Anyway, here you go - add this type of code to your VM:private const Brush greenBrush = new SolidColorBrush(Colors.Green);
private const Brush redBrush = new SolidColorBrush(Colors.Red);
private Brush currentBrush;
private int oldValue;
private int currentValue;
public Brush Background
{
get { return currentBrush; }
}
public int CurrentValue
{
get
{
return currentValue;
}
set
{
if (currentValue == value) return;
oldValue = currentValue;
currentValue = value;
if (oldValue < currentValue)
currentBrush = redBrush;
else
currentBrush = greenBrush;
OnChanged("CurrentValue");
OnChanged("CurrentBrush");
OnChanged("Difference");
}
}
public int Difference
{
get { return Math.Abs(currentValue - oldValue); }
}And that's it - bind the BackgroundValue to Background to get the background colour to respond to changes.
|
|
|
|

|
What's wrong with putting a color in the VM? That's kind of its job. To contain all the properties that the view needs to render the model. That's totally MVVM.
|
|
|
|

|
The reason you do not want the color in the ViewModel is that the viewmodel should not be concerned with View issues. The color is a something for the View since it is purely UI. This is just like having the ViewModel provide Visibility enumerations. The ViewModel should not have to worry about if you are in WPF or something else. Obviously there is nothing else besides Silverlight, which is the same, but that does not have to be the case.
|
|
|
|

|
That is the VM's job. To re-package the model for the view and to implement all the RelayCommands, etc. Visiblity, colors, widths, etc. are all appropriate for the VM. Otherwise, where do you draw the line? Say I have a listview. Now, you are saying the columns should not be in the VM because that is a view issue?
|
|
|
|

|
From Wikipedia:
View model: the view model is a “model of the view” meaning it is an abstraction of the view that also serves in mediating between the view and the model which is the target of the view data bindings. It could be seen as a specialized aspect of what would be a controller (in the MVC pattern) that acts as a converter that changes model information into view information and passes commands from the view into the model. The view model exposes public properties, commands, and abstractions. The view model has been likened to a conceptual state of the data as opposed to the real state of the data in the model.[10] The term "View model" is a major cause of confusion in understanding the pattern when compared to the more widely implemented MVC or MVP patterns. The role of the controller or presenter of the other patterns has been substituted with the framework binder (e.g., XAML) and view model as mediator and/or converter of the model to the binder.
Color is not an abstraction. You should be able to replace the View with a totally different implementation and still work. Color is part of the GUI, and not an abstraction of the Model, it is a requirement of the View. If it is decided that a different color should be used, that should not affect the ViewModel, any more than changing the position of the textbox should affect the ViewModel. Otherwise why not just go back to WinForms.
|
|
|
|

|
Clifford Nelson wrote: acts as a converter that changes model information into view information and
passes commands from the view into the model. The view model exposes public
properties, commands, and abstractions. The view model has been likened to a
conceptual state of the data as opposed to the real state of the data in the
model.
Sounds like the color would fit that description quite nicely IMO. Its an abstraction of a value change in this case. An up-tick is green and a down-tick is red. That's an abstraction.
Clifford Nelson wrote: Color is not an abstraction. You should be able to replace the View with a
totally different implementation and still work.
Having an up-tick color and a down-tick color exposed in the VM has no effect on swapping out the View whatsoever. Any View can either use it or not.
Clifford Nelson wrote: If it is decided that a different color should be used, that should not affect
the ViewModel, any more than changing the position of the textbox should affect
the ViewModel.
You are really reaching with that one . A color in this case is an abstraction of the up-tick / down-tick concept.
Anyways, I'd REALLY hate to have to maintain your code where every VM has dozens of value converters just for the heck of it. Seems like a nightmare to me . If you are working on a big UI where there are 50 views, you are really going to have 500+ converters??? Are you serious???
And if you REALLY want to be an anal MVVM / OOP purist... the color change doesn't belong in either place. That belongs in a refactored "Cell" object .
|
|
|
|

|
private void combogroup_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
------binded combobox
------
category ca = new category();
strCurCatGroup = combogroup.SelectedValue.ToString().Trim();
ca.changecategory(strCurCatGroup);
}
private void changecategory(string strCategoryGroup)
{
switch(---)
{
case "A":
groupbox1.visibility=Visibility.Hidden;
groupbox2.visibility=Visibility.Visible;
--
case "B":
groupbox1.visibility=Visibility.Visible;
groupbox2.visibility=Visibility.Hidden
}
|
|
|
|

|
Pray tell me sir, why have you dumped a bunch of code in our forum?
See that is a question, it is what we use when trying to get some help in a forum!
Never underestimate the power of human stupidity
RAH
|
|
|
|

|
so,can u help me how to do ?
|
|
|
|

|
Can I help you to do what you have not asked a question, explained what you want or described what your problem is. All you have done is dump some poorly written code into the forum. Read the guidelines at the top of the page on how to ask a question!
And please don't use txt speak.
Never underestimate the power of human stupidity
RAH
|
|
|
|

|
Hi,
I am creating an application in WPF using MVVM pattern. My requirement is to use a grid which should support dynamic row creation and columns are not static , it will be vary always depends on the selection.
Please help to achieve it.
Thanks in advance,
Selvam S
|
|
|
|

|
You should have not problem with creating a completely dynamic environment with WPF and a DataGrid. I have the following xaml:
<Window x:Class="DynamicGrid.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:DynamicGrid"
Title="MainWindow"
Height="350"
Width="525">
<Window.DataContext>
<local:ViewModel />
</Window.DataContext>
<Grid>
<DataGrid AutoGenerateColumns="True"
ItemsSource="{Binding Children}"
HorizontalAlignment="Stretch"
Name="dataGrid1"
VerticalAlignment="Stretch" />
</Grid>
</Window>
with the following ViewModel:
class ViewModel
{
public ViewModel()
{
var temp = new BindingList<Class1>();
temp.Add(new Class1 {TypeA = "AAAA", TypeB = "BBBB"});
temp.Add(new Class1 { TypeA = "CCCC", TypeB = "CCCC" });
_children = temp;
}
private IEnumerable<object> _children;
public IEnumerable<object> Children
{
get { return _children; }
set { _children = value; }
}
}
The grid is automatically created, and can add new rows. Just use what ojects you need. If you need something even more dynamic, then can bind to a class that inherits from DynamicObject
|
|
|
|

|
Hi,
I am developing a WPF application in MVVM pattern.
I got stuck in closing a popup window. I will explain how I started my application.
I created Main window, Login User Control and New User window.
In my main window , I used content control to load my login user control. On clicking the new user button in login screen, I initiated new user window and then I filled user registration details in new user window and then clicked OK. Now my new user window must get closed and stay with main window but it is not happening.
But I am not able to close the new user window through my button click.
Kindly help me in this situation and provide me a best approach to solve the issue.
Thanks in advance
Regards,
Selvam S
|
|
|
|

|
Personally I use code behind to handle the click event of the button and set the DialogResult. Any processing of the data is done in the VM and is called from the code behind.
Never underestimate the power of human stupidity
RAH
|
|
|
|

|
This[^] is a fairly common solution to this problem.
|
|
|
|

|
If you look at the Prism samples[^], you will find a good solution that you could use to implement a self-closing popup dialog.
Just handle the mouse click event on the shell and you can close any popups that are open on the shell.
|
|
|
|
 |