Bool Visibilità Converter in WPF

Ho tre pulsanti di opzione e tre le caselle di gruppo e in base alla selezione del pulsante, casella di gruppo dovrebbe essere stato visibile o crollate, ma nulla sembra funzionare qui. Il codice per il mio costruttore viene eseguito, ma ancora sembra che le cose si sovrappongono a vicenda.

<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>

Qui è il codice per il convertitore

    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();
        }
    }
}
Dove è il codice del tuo Convertitore?
Ho aggiunto. Si prega di dare un’occhiata.
Aaaaand è andato ….
Incollare tutti Window codice
Hai dichiarato la risorsa in Finestra.Le risorse ?

InformationsquelleAutor MegaMind | 2013-08-16

1 risposta

  1. 4

    Modificare il Visibility associazione:

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

    Quindi aggiungere una proprietà IsMonthlyInterestChecked al tuo ViewModel e associare RadioButton:

    <RadioButton Grid.Column="0" x:Name="rdbMonthlyInterest"  
        Content="Monthly Interest" 
        Style="{StaticResource RadioButtonWhite}" 
        IsChecked="{Binding IsMonthlyInterestChecked}"/>
    Ho aggiunto il codice completo per il mio controllo utente in questione. Vedere se si può fare di qualsiasi aiuto
    No, non avete. Ancora non riesco a vedere che gli spazi dei nomi non si utilizza. Perché non si può semplicemente copiare e incollare TUTTO il codice per la domanda?
    Scusa pensavo che non era importante. Ho aggiunto che ora.
    hai cambiato gli spazi dei nomi? Nel precedente modifica non c’era alcuna menzione di Finance.MainUI.Common.Converters, che è un errore troppo

    InformationsquelleAutor Andrey Gordeev

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *