0
Reply

IMultiValueConverter converter problem???

vladc

vladc

Oct 24 2010 3:29 PM
8.4k

Hello, I am tryng to write a multibinding converter for a navigation model where I load pages into a frame when any listboxitem is selected from two listboxes. At the same time, I need to be able to navigate with Back/Forward buttons from the navigation class and being able to show listboxitem in selected state if its UriSource is loaded into the frame. The coverter I have can update urisources from two sources-listboxes in the frame but cannot switch listboxitem in selected state. I switch listboxitem into selected state on ConvertBack portion of the converter. I did something wrong, I am always getting errors on a built. Please let me know if it possible to achieve what I m trying to do. Thank you in advance.
The below is the MultiBindConverter code:
 

public class MultiBindConverter : IMultiValueConverter
{

#region
IMultiValueConverter Members
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (values[0] != null)
{
if (values[1] != null)
{
return new Uri(values[1].ToString(), UriKind.RelativeOrAbsolute);
}
return new Uri(values[0].ToString(), UriKind.RelativeOrAbsolute);
}
return null;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
{
if (value != null)
{
var uri = (Uri)value;
var uriString = uri.OriginalString;
if (uri.OriginalString.Contains(";component/"))
{
uriString = uriString.Substring(uriString.IndexOf(
"/") + 1);
}
return new object[] {uriString, uriString};
}
//return Binding.DoNothing;
}

#endregion
IMultiValueConverter Members
}

 

XAML:
 

<
Frame Grid.Column="2" x:Name="ContentFrame" JournalOwnership="OwnsJournal" NavigationUIVisibility="Visible">
<Frame.Source>
<MultiBinding Converter="{StaticResource MultiBindConverter}">
<Binding Path="SelectedValue" ElementName="Nav_ListBox" Mode="TwoWay" />
<Binding Path="SelectedValue" ElementName="SublevelListbox" Mode="TwoWay" />
</MultiBinding>
</Frame.Source>
</Frame>
 

 
Thank you.