I've created in my project the userControl Node that is defined like this:
<UserControl x:Class="ProjectCrow.Node"
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"
xmlns:local="clr-namespace:ProjectCrow"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Border Name="border" BorderBrush="Black" BorderThickness="1">
<DockPanel LastChildFill="True" Background="AliceBlue" Height="45" Canvas.Top="90" Width="160" MouseRightButtonDown="OnNodeDeselect" MouseLeftButtonDown="OnNodeClick" >
<Border BorderBrush="Black" BorderThickness="1" DockPanel.Dock="Left">
<Image Name="img" />
</Border>
<Border BorderBrush="Black" BorderThickness="1" DockPanel.Dock="Bottom" Height="10" >
<TextBlock Name="protocol" VerticalAlignment="Center" Background="Gold" TextAlignment="Center" TextWrapping="Wrap"> FFI
</TextBlock>
</Border>
<Border BorderBrush="Black" BorderThickness="1" DockPanel.Dock="Top">
<TextBlock Name="nodeName" VerticalAlignment="Center" TextAlignment="Center" TextWrapping="Wrap">UNIT
</TextBlock>
</Border>
</DockPanel>
</Border>
I use it many times in my application. Basically it indicates a node, with a defined IP and Port from which you can obtain some data.
I created a combobox that is used by the user to choose which source node to collect data from. I used data binding to get the list of current availables nodes.
sourcesBox.SetBinding(ComboBox.ItemsSourceProperty, new Binding() { Source = MainUI.mainWindow.sources});
sourcesBox.DisplayMemberPath = "NameString";
sourcesBox.SelectedValuePath = "NameString";
Where the MainUI.mainWindow.Sources
is public ObservableCollection<Node> sources;
I will leave you also the implementation of my partial Node class
public partial class Node : UserControl
{
bool selected = false;
string name;
public string NameString
{
get { return name; }
set { if (name != value)
{
name = value;
NotifyPropertyChanged("NameString");
}
}
}
public virtual event PropertyChangedEventHandler PropertyChanged;
protected virtual void NotifyPropertyChanged(params string[] propertyNames)
{
if (PropertyChanged != null)
{
foreach (string propertyName in propertyNames) PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
PropertyChanged(this, new PropertyChangedEventArgs("HasError"));
}
}
public Node()
{
InitializeComponent();
}
The ComboBox shows correctly all the possible Nodes that currently are available, but if i select something the SelectedValue is not shown.
How can i fix this problem?