views:

100

answers:

1

Imagine:

[RadOutlookBarItem1] [RadOutlookBarItem2] [RadOutlookBar] [CONTENCONTROL]

What i want to achieve is:

User selects one of the RadOutlookBarItem's. Item's tag is bound like:

Tag="{Binding SelectedControl, Mode=TwoWay}" 

MVVM Property

public string SelectedControl 
{ 
    get { return _showControl; } 
    set 
    { 
        _showControl = value; 
        OnNotifyPropertyChanged("ShowControl"); 
    } 
}

ContentControl has multiple CustomControls and Visibility of those is bound like:

   <UserControl.Resources> 
        <Converters:BoolVisibilityConverter x:Key="BoolViz"/> 
    </UserControl.Resources> 
    <Grid x:Name="LayoutRoot" Background="White"> 
        <Views:ViewDocumentSearchControl Visibility="{Binding SelectedControl, Converter={StaticResource BoolViz}, ConverterParameter='viewDocumentSearchControl'}"/> 
        <Views:ViewStartControl Visibility="{Binding SelectedControl, Converter={StaticResource BoolViz}, ConverterParameter='viewStartControl'}"/> 
    </Grid>

Converter:

public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { // here comes the logic part... should return Visibility.Collapsed : Visibility.Visible based on 'object value' value

    System.Diagnostics.Debugger.Break(); 
    return Visibility.Collapsed;  
}

now, logically the object value is always set to null. So here's it comes to my question: How can i put a value into the SelectedControl Variable for the RadOutlookBarItem's Tag. I mean something like

Tag="{Binding SelectedControl, Mode=TwoWay, VALUE='i.e.ControlName'"}

So that i can decide, using the Convert Method, whether a specific Control's visibility is either set to collapsed or visible?

help's appreciated

Christian

--- Solution from Laurent ---

Yes, that's what i want,unfortunately VS.NET 2010 / Blend 4RC crashes after implementing it like this:

<Views:ViewDocumentSearchControl Visibility="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource BoolViz}}"/> <Views:ViewStartControl Visibility="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource BoolViz}}"/> 

whenever i open the XAML in Blend / VS.NET i get a XYZ has stopped working. Changed the ValueConverter's return to Visibility.Visible, still the same. No idea. Thanks anyway! Christian

--- my (temporary) solution/workaround---

Okay, i ended up with this solution:

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value != null && parameter != null)
            {
                var val = (string) value;
                var ctrl = (string) parameter;
                if (val.Equals(ctrl))
                {
                    return Visibility.Visible;
                }
                return Visibility.Collapsed;
            }
            return Visibility.Collapsed;
        }

and set the .Tag of the RadOutlookBarItem in the Codebehind...

A: 

It sounds like you want to pass the current item to the converter and return a Visibility. It is possible that I didn't completely understood what you mean, but if that is the case, this should work for you:

Visibility={Binding RelativeSource={RelativeSource Self}, Converter={StaticResource BoolViz}}

The "value" parameter will be set to the ViewDocumentSearchControl in the first case, and to the ViewStartControl in the second case.

Is that what you were looking for?

Cheers, Laurent

LBugnion
@Christian: Please add code to your question with some supplementary comment rather than include it in a comment where it formats very poorly. Its perhaps one of the most outstanding differences in SO from forums is that editing questions and answers is possible and actively encouraged.
AnthonyWJones