我想在名为CanSelectNextPage的WizardPage属性上使用多重绑定。
向导页连接到扩展的 WPF 工具包包。
我做了:
在 MainWindow.xaml 上:
<xctk:WizardPage x:Name="Page1" PageType="Interior"
Title="DB Configuration-Stage 1"
Description="Select between create new GFACT environment to update existing gfact database"
Background="#FF27E0E0" BorderBrush="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"
Leave="Page1_Leave">
<WizardPage.CanSelectNextPage>
<MultiBinding Converter="{StaticResource CanSelectNextPage1}">
<Binding ElementName ="RadioButNew" Path="IsChecked" Mode="OneWay"/>
<Binding ElementName ="RadioButUpdate" Path="IsChecked" Mode="OneWay"/>
<Binding ElementName ="outputFolder" Path="Text" Mode="OneWay"/>
<Binding ElementName ="reducedModelFolder" Path="Text" Mode="OneWay"/>
</MultiBinding>
</WizardPage.CanSelectNextPage>
<Grid Margin="-5 -10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<RadioButton x:Name="RadioButNew" Content="New" Margin="5 10" FontSize="13.333"/>
<RadioButton x:Name="RadioButUpdate" Content="Update" Margin="5 10" Grid.Column="2" FontSize="13.333"/>
<Label x:Name="outputFolderLabel" Content="Select destination folder:" Height="30" Grid.Row="1" Grid.Column="0" FontSize="13.333" Margin="5 10">
<Label.Visibility>
<MultiBinding Converter="{StaticResource FilterConverter}">
<Binding ElementName ="RadioButNew" Path="IsChecked" Mode="OneWay"/>
<Binding ElementName ="RadioButUpdate" Path="IsChecked" Mode="OneWay"/>
</MultiBinding>
</Label.Visibility>
</Label>
<Label x:Name="reducedFolderLabel" Content="Select reduced model folder:" Height="30" Grid.Row="2" Grid.Column="0" FontSize="13.333" Margin="5 10 ">
<Label.Visibility>
<MultiBinding Converter="{StaticResource FilterConverter}">
<Binding ElementName ="RadioButNew" Path="IsChecked" Mode="OneWay"/>
<Binding ElementName ="RadioButUpdate" Path="IsChecked" Mode="OneWay"/>
</MultiBinding>
</Label.Visibility>
</Label>
<TextBox x:Name="outputFolder" Width ="200" Height="30" Grid.Row="1" Grid.Column="1" Margin="5 10">
<TextBox.Visibility>
<MultiBinding Converter="{StaticResource FilterConverter}">
<Binding ElementName ="RadioButNew" Path="IsChecked" Mode="OneWay"/>
<Binding ElementName ="RadioButUpdate" Path="IsChecked" Mode="OneWay"/>
</MultiBinding>
</TextBox.Visibility>
</TextBox>
<TextBox x:Name="reducedModelFolder" Width ="200" Height="30" Grid.Row="2" Grid.Column="1" Margin="5 10">
<TextBox.Visibility>
<MultiBinding Converter="{StaticResource FilterConverter}">
<Binding ElementName ="RadioButNew" Path="IsChecked" Mode="OneWay"/>
<Binding ElementName ="RadioButUpdate" Path="IsChecked" Mode="OneWay"/>
</MultiBinding>
</TextBox.Visibility>
</TextBox>
<Button x:Name="outputFolderOpenBut" Content="" Grid.Row="1" Grid.Column="2" Width="30" Height="30" VerticalAlignment="Top" Margin="5 10" >
<Button.Background>
<ImageBrush ImageSource="OpenPL.bmp" />
</Button.Background>
<Button.Visibility>
<MultiBinding Converter="{StaticResource FilterConverter}">
<Binding ElementName ="RadioButNew" Path="IsChecked" Mode="OneWay"/>
<Binding ElementName ="RadioButUpdate" Path="IsChecked" Mode="OneWay"/>
</MultiBinding>
</Button.Visibility>
</Button>
<Button x:Name="reducedModelFolderOpenBut" Content="" Grid.Row="2" Grid.Column="2" Width="30" Height="30" VerticalAlignment="Top" Margin="5 10" >
<Button.Background>
<ImageBrush ImageSource="OpenPL.bmp" Stretch="Uniform"/>
</Button.Background>
<Button.Visibility>
<MultiBinding Converter="{StaticResource FilterConverter}">
<Binding ElementName ="RadioButNew" Path="IsChecked" Mode="OneWay"/>
<Binding ElementName ="RadioButUpdate" Path="IsChecked" Mode="OneWay"/>
</MultiBinding>
</Button.Visibility>
</Button>
</Grid>
</xctk:WizardPage>
在 MainWindow.xaml 上.cs:
public class CanSelectNextPage1 : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (values[0] is bool && values[1] is bool && values[2] is string && values[3] is string)
if (((bool)values[0] || (bool)values[1]) && (values[2] != null) && (values[3] != null))
{
return true;
}
return false;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
出现错误"WPF 不支持向导页":
<WizardPage.CanSelectNextPage>
我假设这是语法问题 - 有人可以帮我吗?我是WPF的新手。
它应该是
<xctk:WizardPage.CanSelectNextPage>
<MultiBinding Converter="{StaticResource CanSelectNextPage1}">
<Binding ElementName="RadioButNew" Path="IsChecked" Mode="OneWay"/>
<Binding ElementName="RadioButUpdate" Path="IsChecked" Mode="OneWay"/>
<Binding ElementName="outputFolder" Path="Text" Mode="OneWay"/>
<Binding ElementName="reducedModelFolder" Path="Text" Mode="OneWay"/>
</MultiBinding>
</xctk:WizardPage.CanSelectNextPage>