I had to rewrite my problem. The blackquoted part below is this post before the edit.
I have two properties : capacitiveCurrent
and ShowProductSum
.
Before any changes in my MVVM application I used to bind capacitiveCurrent
with a value that was set in the contructor - it was 15 always.
capacitiveCurrent
is placed in a different class LineOut
, code :
capacitiveCurrent property
private double _capacitiveCurrent;
public double CapacitiveCurrent
{
get { return _capacitiveCurrent; }
set
{
if (_capacitiveCurrent != value)
{
_capacitiveCurrent = value;
OnPropertyChanged("_capacitiveCurrent");
}
}
}
The second property is placed in MainWindow.xaml.cs
code:
ShowProductSum
public double _showProductSum;
public double ShowProductSum
{
get { return _showProductSum; }
set
{
if (_showProductSum != value)
{
_showProductSum = value;
OnPropertyChanged("ProductSum");
}
}
}
The logic behing setting and getting ShowProductSum
is done.. almost. But what I expect from those two properties is that I want them to show up in the ComboBox. This is what I have:
private ObservableCollection<double> _comboBoxCapacitiveCurrent = new ObservableCollection<double>();
public ObservableCollection<double> ComboBoxCapacitiveCurrent
{
get
{
_comboBoxCapacitiveCurrent.Clear();
_comboBoxCapacitiveCurrent.Add(lineWy.capacitiveCurrent);
_comboBoxCapacitiveCurrent.Add(ShowProductSum);
return _comboBoxCapacitiveCurrent;
}
set
{
if (_comboBoxCapacitiveCurrent != value)
{
_comboBoxPradPojemnosciowy = value;
OnPropertyChanged("ComboBoxCapacitiveCurrent");
}
}
}
public double SelectedItem { get; set; }
ComboBox:
<DataGridTemplateColumn Header="Capacitive Current " HeaderStyle="{StaticResource ZwarcioweHeaderStyle}">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox
ItemsSource="{Binding Path=ComboBoxCapacitiveCurrent}"
SelectedValue="{Binding Path=SelectedItem, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
>
</ComboBox>
</DataTemplate></DataGridTemplateColumn.CellTemplate></DataGridTemplateColumn>
CombBox is present but nothing is in the dropdownlist of combobox.Some blank space just underneath this combobox. Everything implements INotifyPropertyChanged interface.
Thanks in advance.
I'm an absolute beginner in MVVM C#. I'm trying to bind two properties which are located in two different classes.
First property is
public double capacitiveCurrent { get; set; }
from one class and until then I used this property to View it with a normal binding - the initialized value was shown.public double productLengthShortCircuitCurrent { get { return length* capacitiveShortCircuitCurrentwithGround; } set { } } is a combination of the two `length` and `capacitiveShortCircuitCurrentwithGround` both with getters and
setters.
ComboBox is placed inside
`<DataGridTemplateColumn Header"ABC"> <DataGridTemplateColumn.CellTemplate <DataTemplate> <ComboBox .../>`
What I'm trying to do is having those two properties listed in a ComboBox and:
- I need
capacitiveCurrent
to be editable from the View,
- The
productLengthShortCircuitCurrent
should be a sum of all the set values ( so a sum product).. should I call a function to do such and then bind it to the ComboBox?**I've maged to set and get this property and achieved to get the
ProductSum
property below.. It is all about displaying the two properties in a ComboBox.I'm really confused. Searched for an answer for two days, didn't come up with an idea. Maybe me knowledge is to shallow but... Tried to bind those two properties to an interface with something like
public IConnectedProperties Categories
and a private_category
list with getter and setter.