|
Is it possible to bind different enums to one DataGridComboBoxColumn?
I need to display a couple of physical properties like temperatur, pressure, weight in a datagird. All these physical properties have a name, a physical unit and a value.
<br />
Public Class physicalProperty<br />
<br />
Public Property name() As [Enum]<br />
Get<br />
....<br />
End Get<br />
Set(ByVal value As [Enum])<br />
...<br />
End Property<br />
<br />
<br />
Public Property unit() As [Enum]<br />
Get<br />
....<br />
End Get<br />
Set(ByVal value As [Enum])<br />
...<br />
End Property<br />
<br />
<br />
Public Property value() As double<br />
Get<br />
....<br />
End Get<br />
Set(ByVal value As double)<br />
...<br />
End Property<br />
<br />
End Class<br />
Each row of my datagird should show one physical property. The first column displays the name, the second the unit and
the third the value of the phy. property.
I would like to be able to change the unit in the datagrid with the help of a combobox.
All solutions I found for binding a enum to a datagridComboboxColumn used a ObjectDataProvider to set the itemssource for the datagridCombobox:
<br />
<ObjectDataProvider MethodName="GetValues"<br />
ObjectType="{x:Type sys:Enum}"<br />
x:Key="AlignmentValues"><br />
<ObjectDataProvider.MethodParameters><br />
<x:Type TypeName="namespace:myEnum" /><br />
</ObjectDataProvider.MethodParameters><br />
</ObjectDataProvider><br />
<br />
But I don't have one enum. I have for each physical property one enum ( temperature (K, C, F), pressure (bar, Pa), weight (kg, g)).
Maybee I can use one enum for all physical units and dispaly only the valid ones by filtering?
Is there a way to meet my requirements?
reibor
|
|
|
|
|
Well, you're not using the MVVM pattern. You should implement the MVVM pattern when you're using WPF (although you sometimes can take shortcuts and not implement the necessary parts to get the job done).
You can learn about MVVM from the links I posted here[^].
So I suggest you create a class PhysicalPropertyViewModel that has the following main properties
- a property AvailableUnits that returns the available enum values for the property (to feed the combobox)
- and a property SelectedUnit that is bound to the SelectedItem of the combobox
when is set, it changes the DisplayValue property value accordingly
- a property DisplayValue which is the value to display according to the selected measurement unit
The TreeView article is how I initially understood most of the MVVM concept. Go read it and then read the MSDN Magazine article. Then read this reply again. After this, if you don't understand what I mean, tell me and I'll try to be more clear. Have a nice day.
Eslam Afifi
|
|
|
|
|
Thanks Eslam Afifi, your suggestion to create a property AvailableUnits was the food for thought I needed. It works perfectly.
I am not quite sure if I actually use something like a MVVM pattern. I have a wrapper class for the binding to the GUI. Extended by the AvailableUnits property it works.
Thanks for your help.
reibor
|
|
|
|
|
Glad to help. What you're doing is similar to (if not actually is) the MVVM pattern. MVVM is short for Model-View-ViewModel. A ViewModel is basically a wrapper around a Model for a View to expose the model's properties to the view and to pass commands from the view to the model.
Eslam Afifi
modified on Sunday, November 22, 2009 4:45 PM
|
|
|
|
|
Hi,
I wish to know how can one traverse through items inside a Listbox in WPF. Basically I wants to access the checkbox inside the template.
WPF Code:
|
|
|
|
|
Using the MVVM pattern can help in virtually all cases avoid stuff like that. Please see this post[^].
But if you really need to get it done the way to described, the ListBox has a property called Items. Then for each item, you can access it's visual tree and search for the element you want by its name using the FindName method (I'm not fully sure about that since I did this kind of stuff only once when I first started learning WPF).
P.S. stepping into the debugger and seeing the items' structures using the Immediate Window or a debugger visualizer like Mole[^] can help you get this done quickly.
Eslam Afifi
|
|
|
|
|
hi to all,
i done ssrs report(RDL) using asp.net.Now i need to this implement with silverlight.Is it possible or not.If possible how can i implement give me solution.
Thanks,
sundar
|
|
|
|
|
|
Hello, i am looking for the best wpf chart software / tool for wpf.
It doesnt matter if it costs or not (or how much). The most important thing is, to customize the
charts as much as possible.
|
|
|
|
|
If you need the charts to do dynamic update then check out the D3 project on codeplex: http://dynamicdatadisplay.codeplex.com/Thread/List.aspx
|
|
|
|
|
Hi,
i have text box to enter the name, add button,listbox will display the added records,button to save the record.
when i entered the name and clicked add button, it will add the data to database and text box will be cleared.
like that i adding some records and those records will be binded to listbox and it will display the records in the list box.
now i am trying to edit the record so i just selecting the record in listbox. by doing that i will get the corresponding data in the same text box(Which i used to enter the data).i binded the listbox selected item
to the text box.
then i edited text box and i clicked save button, its saved.
while i saving it i am clearing the text box but due to clearing the text box in save button is clearing the data which is binded in the list box , so the listbox displays the empty data for that record.
Thank's,
|
|
|
|
|
Hi
Some one please explain me outofBrowser concept. I need some clarification below
1.if i installed the application from web to local. which location path out appliation get installed.
2.if i used WCF service in web. how it will work in my local system.(assume i removed internet connection after i installed)
3. Is it possible to access data from a database on the internet when the application is running out of browser and there is no internet access?
4 What all are the security issues posed on the application when running it out of browser.
Regards
Gopal
|
|
|
|
|
You might find this[^] tutorial useful. Also note that "out of browser" doesn't necessarily mean "running disconnected".
/ravi
|
|
|
|
|
Hi
Thanks for reply. They mentioned about how to create OOB.
But my doubts is which path application are installed. since it is use full to click the shotcut inorder to execute the application again.
Regards
Gopal
|
|
|
|
|
Hi there,
I have a WinForm application written in C#. I have added a WPF usercontrol added to the Winform and I want to get the mouse Events passed back to the WinForm.
So you can see in my XAML I have a MouseUp event:
UserControl x:Class="CustomRssFeed.MainWin"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="41" Width="699" Foreground="#FFFFFFFF" Loaded="MainWin_Loaded" Unloaded="MainWin_Unloaded"
SizeChanged="MainWin_SizeChanged"
MouseUp="UserControl_MouseUp"
and I have a XAML.CS with:
private void UserControl_MouseUp(object sender, MouseButtonEventArgs e)
{
}
My question is how do I convert the MouseButtonEventArgs e to a friendly WinForm version of MouseEventArgs ???
|
|
|
|
|
What about subscribing to the event(s) on the ElementHost object
instead?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
unfortunately the ElementHost appears to be very rudimentary but thanks for the thought.
|
|
|
|
|
Hello
I am getting the following error.
"An error occurred while processing this request."
My code is as bellow:
private void btnShow_Click(object sender, RoutedEventArgs e)
{
Uri ur = new Uri(System.Windows.Browser.HtmlPage.Document.DocumentUri,"WebDataService1.svc");
WapCosEntities context = new WapCosEntities(ur);
var query = from u in context.UserMgmt
orderby u.ECode
select u;
var dsQuery = (DataServiceQuery<UserMgmt> )query;
dsQuery.BeginExecute(result => lstCustomers.ItemsSource = dsQuery.EndExecute(result), null);
int i = lstEmpCode.Items.Count;
}
Help me please.
|
|
|
|
|
rag_Singh wrote: Uri ur = new Uri(System.Windows.Browser.HtmlPage.Document.DocumentUri,"WebDataService1.svc");
Use the following & check if it resolves your problem:
ur = new Uri(App.Current.Host.Source, "../WebDataService1.svc");
Regards,
- Kunal Chowdhury ( My Blog)
|
|
|
|
|
I want to know how to do something like this in WPF.
Graphics gfx = MainForm.CreateGraphics();
gfx.DrawRectangle(new SolidBrush(Color.Blue), 0, 0, 100, 100);
I don't want to deal with WPF controls, windows, and XAML at this point. I just want hardware accelerated rendering of simple graphics. Particularly images and rectangles.
|
|
|
|
|
Override the OnRender method of the window. The DrawingContext it gives you should do what you need.
|
|
|
|
|
Like I said. I want to draw with WPF, but I don't want to deal with WPF windows/controls, and XAML.
|
|
|
|
|
Ah, ok, so you want to embed a WPF drawing surface inside WinForms. Well, you'll need at least one WPF control, if you want to use WPF drawing methods...
Here's a decent-looking google hit: http://www.switchonthecode.com/tutorials/wpf-tutorial-using-wpf-in-winforms[^]
You should be able to skip the XAML part of that tutorial, if you just want a drawing surface... Inherit an ElementHost, put it on your form, override the OnRender method, etc etc.
|
|
|
|
|
CaptainSeeSharp wrote: Graphics gfx = MainForm.CreateGraphics();
This is always bad code, unless you're drawing a rubber band.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
The one which comes with PaintEventArgs is the correct way, is it?
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|