|
This is a bit long but please bear with me as I'm stuck. This is a C#/WPF app. The problem is C# so I posted this here.
I am creating a Property Sheet user control. Think of the Visual Studio property sheet. The first pass will simply be a two-column grid with a Caption in the left column and a UI element in the right columm (TextBox, CheckBox, ComboBox).
This control will embedded into a larger UI that allows the user to change the settings used int a Testing Application, without the need to recompile the app.
Data
The settings will be serialized/deserialized in an XML file:
<_TestSettingsBase xsi:type="BeadBeatingMotorSettings">
<TestName>Bead Beating</TestName>
<TestType>BeadBeating</TestType>
<BeadBeaterMax>
<Caption>Bead Beater Max</Caption>
<Description>Bead Beater maximum</Description>
<CurrentValue>
<Value>1</Value>
<Value1>1</Value1>
</CurrentValue>
<DefaultValue>
<Value>1</Value>
<Value1>1</Value1>
</DefaultValue>
<ValueMax>
<Value>0</Value>
<Value1>0</Value1>
</ValueMax>
<ValueMin>
<Value>100</Value>
<Value1>100</Value1>
</ValueMin>
</BeadBeaterMax>
<BeadBeaterMin>
<Caption>Bead Beater Min</Caption>
<Description>Bead Beater minimum</Description>
<CurrentValue>
<Value>0.075</Value>
<Value1>0.075</Value1>
</CurrentValue>
<DefaultValue>
<Value>0.075</Value>
<Value1>0.075</Value1>
</DefaultValue>
<ValueMax>
<Value>101</Value>
<Value1>101</Value1>
</ValueMax>
<ValueMin>
<Value>999</Value>
<Value1>999</Value1>
</ValueMin>
</BeadBeaterMin>
</_TestSettingsBase>
In the XML above the base setting class has TestName and TestType properties
[Serializable]
public class _TestSettingsBase
{
public string TestName { get; set; }
public TestType TestType { get; set; }
}
Then, each individual Test class will inherit from that
[Serializable]
public class BeadBeatingMotorSettings : _TestSettingsBase
{
[ShowInPropertySheet()]
public Setting BeadBeaterMax { get; set; }
[ShowInPropertySheet()]
public Setting BeadBeaterMin { get; set; }
public BeadBeatingMotorSettings()
{
TestType = TestType.BeadBeating;
BeadBeaterMax = new Setting
{
Caption = "Bead Beater Max",
CurrentValue = 1,
DefaultValue = 1,
Description = "Bead Beater maximum",
ValueMax = 0,
ValueMin = 100
};
BeadBeaterMin = new Setting
{
Caption = "Bead Beater Min",
CurrentValue = 0.075,
DefaultValue = 0.075,
Description = "Bead Beater minimum",
ValueMax = 101,
ValueMin = 999
};
}
}
The test's properties are defined as a generic type property I called Setting<t>
[Serializable]
public class Setting : _EntityBase
{
public string Caption { get; set; }
public string Description { get; set; }
public MyProp CurrentValue { get; set; }
public MyProp DefaultValue { get; set; }
public MyProp ValueMax { get; set; }
public MyProp ValueMin { get; set; }
}
public class MyProp
{
private T _value;
public T Value
{
get { return Value1; }
set { Value1 = value; }
}
public T Value1 { get => _value; set => _value = value; }
public static implicit operator T(MyProp value)
{
return value.Value;
}
public static implicit operator MyProp(T value)
{
return new MyProp { Value = value };
}
}
So far everything works great. The data is serialized/deserialized perfectly.
Property Sheet
This is where I'm having trouble.
The PropertySheet is a DataGrid with two columns. The left column is the property's caption and the and right column has a UI element to display the value (TextBox, CheckBox, ComboBox). So far, I created a small User Control for each type of data I expect to deal with.
For example, for Double, I have a UC called DoublePropertyView. It's XAML is this
<UserControl x:Class="PropSheet.PropertyViews.DoublePropertyView"
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:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="100"
d:DesignWidth="100">
<TextBox Text="{Binding SettingValue}"/>
</UserControl>
The code behind has a DependencyProperty called "SettingValue" that the TextBox is bound to. Nothing more than that.
I have one small UC for each type of data - double, int, float, bool, string, etc.
Then the DataGrid's right column uses a TemplateSelector to determine which UC to load into the cell.
The PropertySheet UC has a DP called Settings that takes a list of _TestSettingsBase.
Problem
When I set the list of properties on the DP I then need to reflect each of the properties on the Test class and load into the grid only those properties with the custom attribute ShowInPropertySheet(true).
In the code above you can see on the BeadBeating test class there are two properties, BeadBeaterMin and BeadBeaterMax.
I want these two to appear in the property sheet. Notice that they're marked with the ShowInPropertySheet attribute. When shown in the property sheet I want the Caption and CurrentValue to appear.
Here's my LoadProperties code with the problem. I loop through each Test class in the Settings DP and create a model for each. The list of models is bound to the grid
private void LoadProperties()
{
Properties = new List<PropertyModel>();
var propertyInfos = from pi in Setting.GetType().GetProperties()
let attrs = pi.GetCustomAttributes(typeof(ShowInPropertySheetAttribute), true)
where attrs.Length != 0 &&
(bool)Helpers.GetAttributeValue(Setting.GetType(), pi.Name, typeof(ShowInPropertySheetAttribute), "IsVisible")
select pi;
foreach (PropertyInfo propertyInfo in propertyInfos)
{
var settingProperty = (Setting<double>)propertyInfo.GetValue(Setting);
var current = settingProperty.CurrentValue;
var model = new PropertyModel(propertyInfo.Name, current.Value);
Properties.Add(model);
}
}
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
modified 30-May-18 13:59pm.
|
|
|
|
|
|
Slightly tricky to follow, since your generic type parameters seem to be missing from your code blocks.
Assuming PropertyModel is not generic, and the value is an object , you probably need to have a non-generic interface to read the value. For example:
interface ISetting
{
object CurrentValue { get; }
}
class Setting<T> : _EntityBase, ISetting
{
ISetting.CurrentValue => CurrentValue.Value;
...
}
...
foreach (PropertyInfo propertyInfo in propertyInfos)
{
var settingProperty = (ISetting)propertyInfo.GetValue(Setting);
var model = new PropertyModel(propertyInfo.Name, settingProperty.CurrentValue);
Properties.Add(model);
}
NB: If you'd rather avoid writing your own property grid, there's one included with the free version of the Extended WPF Toolkit:
PropertyGrid · xceedsoftware/wpftoolkit Wiki · GitHub[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Richard Deeming wrote:
NB: If you'd rather avoid writing your own property grid, there's one included with the free version of the Extended WPF Toolkit:
PropertyGrid · xceedsoftware/wpftoolkit Wiki · GitHub[^] Oeh, nice
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Richard Deeming wrote: NB: If you'd rather avoid writing your own property grid, there's one included with the free version of the Extended WPF Toolkit:
PropertyGrid · xceedsoftware/wpftoolkit Wiki · GitHub[^]
That's nice. Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Have you used the WP Extended WPF Toolkit's PropertyGrid?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
No, I've not had a use for it yet.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi,
I have console application that call some API that is working fine
https://www.xxxxxxco.il/QA/xxxServiceFront/xxxx.asmx
but when i tying to call this API from a WCF Service on IIS EXpress or On IIS in server 2012 i am getting this error:
Unable to connect to remote server
There was no endpoint listening at https://www.xxxxxxco.il/QA/xxxServiceFront/xxxx.asmx that could accept the message. This is often caused by an incorrect address or SOAP action.
why there a difference between IIS express and the console application?
|
|
|
|
|
As you haven't presented any code at all, despite this being a C# forum, we're only going to be able to take wild guesses. My best guess would be that your issue is going to be down to identity. The console application runs as your user while IIS is not. I suspect the service is going to expect authentication.
This space for rent
|
|
|
|
|
Hi,
this is the code that is working fine in console application, but on WCF service its getting the communication error:
BDISR.XmlBDIOnLineSoapClient _proxy = new BDISR.XmlBDIOnLineSoapClient();
EndpointAddress endPointAddress = new EndpointAddress("https://www.xxxxxx/QA/xxxx.asmx");
BasicHttpBinding binding = bindingHelper.GetBinding();
binding.Security.Mode = BasicHttpSecurityMode.Transport;
binding.Security.Transport.Realm = "";
binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
binding.Security.Message.AlgorithmSuite = System.ServiceModel.Security.SecurityAlgorithmSuite.Default;
_proxy.Endpoint.Address = endPointAddress;
_proxy.Endpoint.Binding = binding;
_proxy.ClientCredentials.UserName.UserName = "xxx";
_proxy.ClientCredentials.UserName.Password = "xxx";
WebRequest.DefaultWebProxy.Credentials = CredentialCache.DefaultNetworkCredentials;
BDISR.DoBusinessProcessRequest bdiReq = new BDISR.DoBusinessProcessRequest();
bdiReq.Body = new BDISR.DoBusinessProcessRequestBody();
XElement xElementReq = ... some object
bdiReq.Body.req = xElementReq;
BDISR.DoBusinessProcessResponse res = _proxy.DoBusinessProcess(bdiReq);
|
|
|
|
|
Hi,
Please help me on how to get outlook email attachments and save it to local folder using c#.net
Tried many online examples, please share if you have working code on the same.
Thanks in advance
Regards
RaghuB
|
|
|
|
|
|
|
button (Add, Delete, Shearch) with UserControle and saved entity framworks
|
|
|
|
|
Did you have a question or what?
|
|
|
|
|
And what is your question?
modified 20-Sep-20 21:01pm.
|
|
|
|
|
That's a mid-term project, not a question.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Hi, I need example for writing and reading MD file in C# . Thanks
|
|
|
|
|
Would you mind explaining what an "MD file" is?
|
|
|
|
|
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
So explain what an "MD" file is - the only one I'm aware of is a Markdown text file, and that's trivial to read:
string text = File.ReadAllText(pathToFile);
Then explain what problem you are having reading and writing it - we have no idea where you are stuck, so we really can't help you yet.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
I need coffee.
Thanks.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Hi, MD file is Markdown, I want to create it then save some info. in it then read it
|
|
|
|
|
|
Hi, I am a beginner in C# and programming in general. I have a problem getting started with C#, and I need some tips for one project I'm doing for myself.
In general I need a list of items in a combo box, and based on the selection in the combo box I need some variables to take different values, then make calculations based on these values and produce a numerical result into a TextBlock.
For now I understand that I should do it like this (but I am missing a lot):
1. I made a class like this (in MainWindow.xaml.cs):
class Concrete
{
public double CompressionStrength { get; set; }
public double YoungModulus { get; set; }
}
create some instances of this class like this:
Concrete C37 = new Concrete();
C37.ConpressionStrength = "30";
C37.YoungModulus = "21"
Concrete C30 = new Concrete();
C37.ConpressionStrength = "25";
C37.YoungModulus = "21"
2. I made a combo box in MainWindow.xaml
<ComboBox x:Name="ConcreteList">
</ComboBox>
3. Now I need to somehow populate the combo box with different instances of my class, like:
<ComboBox.item1 = C37/>
ComboBox.item2 = C30/>
4. Then I need to create some variables based on the selection in the combo box and make some calculations, for example:
if TextBoxSelection=C37;
double a = 10;
double b = 20;
double CompressionStrength = C37.CompressionStrength;
double c = a*b*CompressionStrength;
else ....
end if
5. And then I just need to print value "c" to a TextBlock in the WPF window.
Now I need to ask for some general guidance about this because I am a little stuck...
1. How do I populate combo box in MainWindow.xaml with names of my class instances that are in the MainWindow.xaml.cs?
2. How do I create a numerical variable from the class property and perform calculatons on it?
3. Is it even doable this way / what would be your suggestions for making this work?
I would be grateful for any comments.
|
|
|
|