2011-05-10 3 views
1

Expression Blend 4에서 Silverlight 응용 프로그램의 프로토 타입을 만들고 있는데 바인딩 된 데이터의 부울 값을 기준으로 ListBox/ComboBox 항목을 표시하거나 숨기려고합니다. 나는이 일을 할 제안 예를 들어 온라인을 발견하지만, 그렇지 않습니다 :이 사용자 제어 화면을로드 할 때 응용 프로그램이 충돌 나는 위의 코드와 같이 (컨테이너 스타일을 주석 처리하지 않는 한Silverlight ListboxItem 가시성 바인딩

<UserControl 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:ed="http://schemas.microsoft.com/expression/2010/drawing" 
    xmlns:local="clr-namespace:PrototypeScreens" 
    mc:Ignorable="d" 
    x:Class="PrototypeScreens.Toolbar" 
    Width="640" Height="31"> 
    <UserControl.Resources> 
     <local:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" /> 
    </UserControl.Resources> 

    <Grid x:Name="LayoutRoot" Background="White"> 
     <ComboBox HorizontalAlignment="Right" Style="{StaticResource ComboBox-Sketch}" VerticalAlignment="Top" Width="32" ItemsSource="{Binding Sites}" > 
      <ComboBox.ItemTemplate> 
       <DataTemplate> 
        <Grid> 
        <ed:RegularPolygon Fill="{StaticResource BaseBackground-Sketch}" ed:GeometryEffect.GeometryEffect="Sketch" HorizontalAlignment="Left" Height="10" InnerRadius="0.47211" Margin="0,0,0,0" PointCount="5" Stretch="Fill" Stroke="{StaticResource BaseBorder-Sketch}" StrokeThickness="2" UseLayoutRounding="False" Width="10" 
         Visibility="{Binding IsFavorite, Converter={StaticResource BooleanToVisibilityConverter}}" />     
        <TextBlock Style="{StaticResource BasicTextBlock-Sketch}" Text="{Binding Name}" HorizontalAlignment="Left" Margin="15,0,0,0" />      
        </Grid> 
       </DataTemplate> 
      </ComboBox.ItemTemplate> 
      <!-- 
      <ComboBox.ItemContainerStyle> 
       <Style TargetType="ComboBoxItem"> 
        <Setter Property="Visibility" Value="{Binding IsRegistered, Converter={StaticResource BooleanToVisibilityConverter}}" /> 
       </Style> 
      </ComboBox.ItemContainerStyle> 
      --> 
     </ComboBox> 
     <ListBox Height="29" Margin="0,0,32,0" Style="{StaticResource ListBox-Sketch}" VerticalAlignment="Top" ItemsSource="{Binding Sites}" ScrollViewer.HorizontalScrollBarVisibility="Hidden"> 
      <ListBox.ItemsPanel> 
       <ItemsPanelTemplate> 
        <StackPanel Orientation="Horizontal" FlowDirection="RightToLeft" /> 
       </ItemsPanelTemplate> 
      </ListBox.ItemsPanel> 
      <ListBox.ItemTemplate> 
       <DataTemplate> 
        <Grid> 
        <TextBlock Style="{StaticResource BasicTextBlock-Sketch}" Text="{Binding Id}" HorizontalAlignment="Left" Margin="0,0,0,0" />       
        <ed:RegularPolygon Fill="{StaticResource BaseBackground-Sketch}" ed:GeometryEffect.GeometryEffect="Sketch" HorizontalAlignment="Left" Height="10" InnerRadius="0.47211" Margin="20,0,0,0" PointCount="5" Stretch="Fill" Stroke="{StaticResource BaseBorder-Sketch}" StrokeThickness="2" UseLayoutRounding="False" Width="10"/>     
        </Grid> 
       </DataTemplate> 
      </ListBox.ItemTemplate> 
      <!-- 
      <ListBox.ItemContainerStyle> 
       <Style TargetType="ListBoxItem"> 
        <Setter Property="Visibility" Value="{Binding IsFavorite, Converter={StaticResource BooleanToVisibilityConverter}}" /> 
       </Style> 
      </ListBox.ItemContainerStyle> 
      --> 
     </ListBox> 
    </Grid> 
</UserControl> 

). 내가 도대체 ​​뭘 잘못하고있는 겁니까?

참고 : ComboBoxItem 내부의 다각형 가시성이 정상적으로 작동합니다.

Webpage error details 

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; MDDC; .NET4.0C; .NET4.0E; BRI/2) 
Timestamp: Tue, 10 May 2011 15:21:02 UTC 


Message: Unhandled Error in Silverlight Application Exception has been thrown by the target of an invocation. at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) 
    at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache) 
    at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache) 
    at System.Activator.CreateInstance(Type type, Boolean nonPublic) 
    at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) 
    at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) 
    at System.Reflection.Assembly.CreateInstance(String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) 
    at Microsoft.Expression.Prototyping.Workspace.PlayerWindow.InstantiateScreen(String screen, Boolean showImmediately) 
    at Microsoft.Expression.Prototyping.Workspace.PlayerWindow.TransitionScreens(String from, String to) 
    at Microsoft.Expression.Prototyping.Navigation.NavigationViewModel.NavigateToScreen(String name, Boolean record) 
Line: 1 
Char: 1 
Code: 0 
URI: file:///D:/Projects/Expression/Prototype/Bin/Debug/Default.html 

UPDATE : 나는 약간의 진전을 생각

UPDATE은 내가 몇 가지 오류 정보를 가지고 전체 UserControl을

UPDATE의 XAML을 포함했다. 바인딩을 해결할 수없는 것 같습니다. ListBox 및 ComboBox는 모두 ItemsSource="{Binding Sites}"이고 SitesSystem.Collections.ObjectModel.ObservableCollection<SitesItem>입니다. SiteItemIsRegisteredIsFavorite의 속성을가집니다.

질문 : 짐을 IsRegisteredIsFavorite에 바인드 할 수 있습니까? ItemContainerStyle에 있습니까?

+1

어디 당신이 당신의'BooleanToVisibilityConverter'에 대한 정적 리소스를 설정하는 데 도움이 다음과 같이 그래서 간단하게 정의? 스타일을 적용하기 전에 생성되지 않았을 수 있습니다. 충돌에 대한 자세한 정보를 제공 할 수 있습니까? –

+0

'BooleanToVisibilityConverter'가 정의되었습니다. –

+0

주문 문제 일 수 있습니다. 스타일을 적용 할 때 변환기가 작성되지 않으면 문제점이있을 수 있습니다. 일을 순서대로 진행할 수 있다면보아야 할 가치가 있습니다. –

답변

0

WPF에는 이미 BooleanToVisibilityConverter가 기본 제공됩니다.

<UserControl.Resources> 
    <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/> 
</UserControl.Resources> 

희망이