XElement unable to perform twoway binding - Readonly



I'm using an Ienumerable<XElement> in a listbox to which I get back the list of elements and display the name attribute. On Selection of those elements the entire element is then displayed in a list box.


However when setting the mode to twoway I am being told that I cannot use two way with a readonly property, despite the set command being unique.


I think I'm having a fundamental misunderstanding and was hoping you could clue me in.


Steps is my collection of all the CS



public IEnumerable<XElement> Steps
{
get
{
if (_XDoc == null) return null;
else
return (_XDoc.Descendants().Where(x => x.Name == ns + "Core"));

}
set
{
XElement xNode = Steps.Elements().Except(value).First();
XElement replaceNode = value.Elements().Except(Steps).First();
_XDoc.ToString().Replace(xNode.ToString(), value.ToString());
}
}


XAML



<ListView HorizontalAlignment="Stretch" Name="listView1" VerticalAlignment="Top" Grid.Column="0" Grid.Row="1"
DataContext="{Binding Steps}" ItemsSource="{Binding Path=/Elements, Mode=TwoWay }" Grid.RowSpan="3">
<ListView.View>
<GridView>
<GridViewColumn Header="Name" DisplayMemberBinding="{Binding Path=Attribute[name].Value}" />
</GridView>
</ListView.View>
</ListView>
<GridSplitter HorizontalAlignment="Left" Height="100" VerticalAlignment="Top" Width="6" Grid.Column="1" Margin="2.6,80,0,0" Grid.Row="2"/>
<WrapPanel Grid.Row="1" Grid.Column="1">
<Label Content="StepID:" Grid.Column="1" HorizontalAlignment="Left" Grid.Row="1" VerticalAlignment="Top" />
<Label Content="{Binding Path=Attribute[stepID].Value}" HorizontalAlignment="Left" VerticalAlignment="Top" DataContext="{Binding SelectedItem, ElementName=listView1, Mode=TwoWay }" />
</WrapPanel>
<TextBox Grid.Column="1" Grid.Row="2" Grid.ColumnSpan="2" Grid.RowSpan="3" Margin="1,0,0,0"
Text="{Binding SelectedItem, ElementName=listView1, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged }" TextWrapping="Wrap" AcceptsReturn="True" >
</TextBox>


Elements is a readonly property, however I see no way around this as when attempting to make calls without linq to childnodes or descendants it returns null.


No comments:

Post a Comment