2013-08-16 31 views
5

Mam trzy przyciski radiowe i trzy pola grupowe i na podstawie wyboru przycisku opcji pole grupy powinno być widoczne lub zwinięte, ale nic nie działa tutaj. Kod mojego konstruktora zostaje wykonany, ale wydaje się, że rzeczy nakładają się na siebie. Konwerter Bool na widoczność w WPF

<baseControls:MaintainTemplate Style="{StaticResource {x:Type baseControls:MaintainTemplate}}" TitleText="{Binding TitleText}"> 

    <baseControls:MaintainTemplate.TabSection> 
     <Grid> 
      <GroupBox> 
       <GroupBox.Header> 
        <TextBlock Text="Case Information" Style="{StaticResource TextBlockWhite}"/> 
       </GroupBox.Header> 
       <GroupBox.Content> 
        <Grid x:Name="GridMain"> 
         <Grid.RowDefinitions> 
          <RowDefinition Style="{StaticResource AutoHeightRowDefinition}"/> 
          <RowDefinition Style="{StaticResource MinHeightRowDefinition}"/> 
          <RowDefinition Style="{StaticResource AutoHeightRowDefinition}"/> 
          <RowDefinition Style="{StaticResource MinHeightRowDefinition}"/> 
          <RowDefinition Style="{StaticResource AutoHeightRowDefinition}"/> 
          <RowDefinition Style="{StaticResource MinHeightRowDefinition}"/> 
          <RowDefinition Style="{StaticResource MaxHeightRowDefinition}"/> 
          <RowDefinition Style="{StaticResource MinHeightRowDefinition}"/> 
         </Grid.RowDefinitions> 
         <Grid.ColumnDefinitions> 
          <ColumnDefinition Style="{StaticResource MinWidthColumnDefinition}"/> 
          <ColumnDefinition Style="{StaticResource MaxWidthColumnDefinition}"/> 
          <ColumnDefinition Style="{StaticResource MinWidthColumnDefinition}"/> 
         </Grid.ColumnDefinitions> 
         <Grid Grid.Column="1" x:Name="GridSelectCustomer"> 
          <Grid.RowDefinitions> 
           <RowDefinition Style="{StaticResource MinHeightRowDefinition}"/> 
           <RowDefinition Style="{StaticResource AutoHeightRowDefinition}"/> 
           <RowDefinition Style="{StaticResource MinHeightRowDefinition}"/> 
           <RowDefinition Style="{StaticResource AutoHeightRowDefinition}"/> 
          </Grid.RowDefinitions> 
          <Grid.ColumnDefinitions> 
           <ColumnDefinition Style="{StaticResource AutoWidthColumnDefinition}"/> 
           <ColumnDefinition Style="{StaticResource MinWidthColumnDefinition}"/> 
           <ColumnDefinition Style="{StaticResource AutoWidthColumnDefinition}"/> 
           <ColumnDefinition Style="{StaticResource MinWidthColumnDefinition}"/> 
           <ColumnDefinition Style="{StaticResource AutoWidthColumnDefinition}"/> 
           <ColumnDefinition Style="{StaticResource MinWidthColumnDefinition}"/> 
           <ColumnDefinition Style="{StaticResource AutoWidthColumnDefinition}"/> 
          </Grid.ColumnDefinitions> 
          <TextBlock Grid.Row="1" Text="Select Customer" Style="{StaticResource TextBlockWhite}"/> 
          <ComboBox Grid.Row="1" Grid.Column="2" Width="150" ItemsSource="{Binding Customers}" 
          DisplayMemberPath="FirstName" SelectedValue="{Binding SelectedCustomer}"/> 
          <Button Grid.Row="1" Grid.Column="4" Content="Quick Search"/> 
          <Button Grid.Row="1" Grid.Column="6" Content="Add New Customer"/> 

          <TextBlock Grid.Row="3" Text="Reference No" Style="{StaticResource TextBlockWhite}"/> 
          <TextBox Grid.Row="3" Grid.Column="2"/> 
          <TextBlock Grid.Row="3" Text="Case No" Grid.Column="4" Style="{StaticResource TextBlockWhite}"/> 
          <TextBox Grid.Row="3" Grid.Column="6" Style="{StaticResource TextBoxReadOnly}"/> 
         </Grid> 
         <GroupBox Grid.Row="2" Grid.Column="1" x:Name="GroupBoxCustomerInfo"> 
          <GroupBox.Header> 
           <TextBlock Text="Customer Details" Style="{StaticResource TextBlockWhite}"></TextBlock> 
          </GroupBox.Header> 
          <GroupBox.Content> 
           <Grid> 
            <Grid.ColumnDefinitions> 
             <ColumnDefinition Style="{StaticResource MinWidthColumnDefinition}"/> 
             <ColumnDefinition Style="{StaticResource AutoWidthColumnDefinition}"/> 
             <ColumnDefinition Style="{StaticResource MinWidthColumnDefinition}"/> 
             <ColumnDefinition Style="{StaticResource AutoWidthColumnDefinition}"/> 
             <ColumnDefinition Style="{StaticResource MinWidthColumnDefinition}"/> 
             <ColumnDefinition Style="{StaticResource AutoWidthColumnDefinition}"/> 
             <ColumnDefinition Style="{StaticResource MinWidthColumnDefinition}"/> 
             <ColumnDefinition Style="{StaticResource AutoWidthColumnDefinition}"/> 
            </Grid.ColumnDefinitions> 
            <Grid.RowDefinitions> 
             <RowDefinition Style="{StaticResource AutoHeightRowDefinition}"/> 
             <RowDefinition Style="{StaticResource MinHeightRowDefinition}"/> 
             <RowDefinition Style="{StaticResource AutoHeightRowDefinition}"/> 
             <RowDefinition Style="{StaticResource MinHeightRowDefinition}"/> 
             <RowDefinition Style="{StaticResource AutoHeightRowDefinition}"/> 
            </Grid.RowDefinitions> 
            <TextBlock Style="{StaticResource TextBlockWhite}" Grid.Row="0" Grid.Column="1" Text="Name"/> 
            <TextBox Style="{StaticResource TextBoxReadOnly}" Grid.Column="3"></TextBox> 
            <TextBlock Style="{StaticResource TextBlockWhite}" Grid.Row="0" Grid.Column="5" Text="Phone No"/> 
            <TextBox Style="{StaticResource TextBoxReadOnly}" Grid.Column="7"></TextBox> 
            <TextBlock Style="{StaticResource TextBlockWhite}" Grid.Row="2" Grid.Column="1" Text="Father's Name"/> 
            <TextBox Style="{StaticResource TextBoxReadOnly}" Grid.Column="3" Grid.Row="2"></TextBox> 
            <TextBlock Style="{StaticResource TextBlockWhite}" Grid.Row="4" Grid.Column="1" Text="Address"/> 
            <TextBox Style="{StaticResource TextBoxMultiLineReadOnly}" Grid.Row="4" Grid.Column="3" ></TextBox> 
            <TextBlock Style="{StaticResource TextBlockWhite}" Grid.Row="2" Grid.Column="5" Text="Date Of Birth"/> 
            <TextBox Style="{StaticResource TextBoxReadOnly}" Grid.Column="7" Grid.Row="2"></TextBox> 

           </Grid> 
          </GroupBox.Content> 
         </GroupBox> 
         <GroupBox Grid.Row="4" Grid.Column="1" x:Name="GroupBoxCaseType"> 
          <GroupBox.Header> 
           <TextBlock Text="Case Type" Style="{StaticResource TextBlockWhite}"/> 
          </GroupBox.Header> 
          <GroupBox.Content> 
           <Grid> 
            <Grid.ColumnDefinitions> 
             <ColumnDefinition Style="{StaticResource MinWidthColumnDefinition}"/> 
             <ColumnDefinition Style="{StaticResource AutoWidthColumnDefinition}"/> 
             <ColumnDefinition Style="{StaticResource MaxWidthColumnDefinition}"/> 
             <ColumnDefinition Style="{StaticResource AutoWidthColumnDefinition}"/> 
             <ColumnDefinition Style="{StaticResource MaxWidthColumnDefinition}"/> 
             <ColumnDefinition Style="{StaticResource AutoWidthColumnDefinition}"/> 
             <ColumnDefinition Style="{StaticResource MinWidthColumnDefinition}"/> 
            </Grid.ColumnDefinitions> 
            <RadioButton Grid.Column="1" x:Name="rdbMonthlyInterest" Content="Monthly Interest" 
            Style="{StaticResource RadioButtonWhite}" IsChecked="{Binding IsMonthlyInterestChecked}"/> 
            <RadioButton Grid.Column="3" x:Name="rdbDailyInstallment" Content="Daily Installment" 
            Style="{StaticResource RadioButtonWhite}" IsChecked="{Binding IsDailyInstallmentChecked}"/> 
            <RadioButton Grid.Column="5" x:Name="rdbMonthlyInstallment" Content="Monthly Installment" 
            Style="{StaticResource RadioButtonWhite}" IsChecked="{Binding IsMonthlyInstallmentChecked}"/> 
           </Grid> 
          </GroupBox.Content> 
         </GroupBox> 
         <GroupBox Grid.Row="6" Grid.Column="1" Visibility="{Binding Path=IsMonthlyInterestChecked, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource VisibilityConverter}}" > 
          <GroupBox.Header> 
           <TextBlock Style="{StaticResource TextBlockWhite}">Monthly Interest</TextBlock> 
          </GroupBox.Header> 
         </GroupBox> 
         <GroupBox Grid.Row="6" Grid.Column="1" Visibility="{Binding Path=IsDailyInstallmentChecked, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource VisibilityConverter}}" > 
          <GroupBox.Header> 
           <TextBlock Style="{StaticResource TextBlockWhite}">Daily Installment</TextBlock> 
          </GroupBox.Header> 
         </GroupBox> 
         <GroupBox Grid.Row="6" Grid.Column="1" Visibility="{Binding Path=InMonthlyInstallmentChecked, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource VisibilityConverter}}" > 
          <GroupBox.Header> 
           <TextBlock Style="{StaticResource TextBlockWhite}">Monthly Installment</TextBlock> 
          </GroupBox.Header> 
         </GroupBox> 
        </Grid> 
       </GroupBox.Content> 
      </GroupBox> 
     </Grid> 
    </baseControls:MaintainTemplate.TabSection> 
</baseControls:MaintainTemplate> 

Oto kod dla przetwornika

namespace Finance.MainUI.Common.Converters 
    { 
    public class BoolToVisibilityConverter : IValueConverter 
    { 
     public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
     { 
      return (bool) value ? Visibility.Visible : Visibility.Collapsed; 
     } 

     public object ConvertBack(object value, Type targetType, object parameter,CultureInfo culture) 
     { 
      throw new NotImplementedException(); 
     } 
    } 
} 
+0

Gdzie jest kod Twojego Converter? –

+0

@AndreyGordeev Dodałem go. Proszę spojrzeć. – MegaMind

+0

Aaaa i zniknęło ... –

Odpowiedz

4

zmienić Visibility wiązania:

<GroupBox Grid.Row="7" Grid.Column="1" 
    Visibility="{Binding 
     RelativeSource={RelativeSource FindAncestor, 
      AncestorType={x:Type UserControl}} 
     Path=DataContext.IsMonthlyInterestChecked, 
     UpdateSourceTrigger=PropertyChanged, 
     Converter={StaticResource VisibilityConverter}}" > 

Następnie dodać pr operty IsMonthlyInterestChecked do ViewModel i wiążą RadioButton do niego:

<RadioButton Grid.Column="0" x:Name="rdbMonthlyInterest" 
    Content="Monthly Interest" 
    Style="{StaticResource RadioButtonWhite}" 
    IsChecked="{Binding IsMonthlyInterestChecked}"/> 
+0

Dodałem pełny kod dla mojej kontroli użytkownika w pytaniu. Sprawdź, czy to mogłoby pomóc. – MegaMind

+0

Nie, nie masz. Nadal nie widzę, których przestrzeni nazw używasz. Dlaczego nie możesz po prostu skopiować i wkleić WSZYSTKIE swój kod do pytania? –

+0

Przepraszam, że myślałem, że to nie jest ważne. Dodałem to teraz. – MegaMind