开发者

Multibinding converter?

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 select开发者_StackOverflow中文版ed 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 };  
       }
   } 
} 

XAML:

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


You aren't implementing the IMultiValueConverter interface. The signature for ConvertBack is:

public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)

It is the exact opposite of Convert which takes in an array and outputs a single value so it needs to take in that single value and output an array of values. The incoming value for ConvertBack in this case would be the Frame.Source and the outputs would be the 2 SelectedValue properties.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜