I would like to use multibinding on property of WizardPage called CanSelectNextPage.
WizardPage connects to Extended WPF toolkit package.
I did:
On 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>
On 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();
}
}
An error "Wizard Page is not supported in WPF" appeared on:
<WizardPage.CanSelectNextPage>
I'm assume it syntax issue- can someone help me please? I'm newbie on WPF..
It should be
<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>
Related
I'm trying to reduce this:
<CheckBox Content="K1" Grid.Row="0" Grid.Column="0">
<CheckBox.IsChecked>
<local2:BcpBinding Path="RelayOutputMask" Converter="{StaticResource ByteBit2Bool}" ConverterParameters="0,Binding Path=RelayOutputMask" Mode="TwoWay" />
</CheckBox.IsChecked>
</CheckBox>
<CheckBox Content="K2" Grid.Row="0" Grid.Column="1">
<CheckBox.IsChecked >
<local2:BcpBinding Path="RelayOutputMask" Converter="{StaticResource ByteBit2Bool}" ConverterParameters="1,Binding Path=RelayOutputMask" Mode="TwoWay" />
</CheckBox.IsChecked>
</CheckBox>
<CheckBox Content="K3" Grid.Row="0" Grid.Column="2">
<CheckBox.IsChecked >
<local2:BcpBinding Path="RelayOutputMask" Converter="{StaticResource ByteBit2Bool}" ConverterParameters="2,Binding Path=RelayOutputMask" Mode="TwoWay" />
</CheckBox.IsChecked>
</CheckBox>
<CheckBox Content="K4" Grid.Row="0" Grid.Column="3">
<CheckBox.IsChecked >
<local2:BcpBinding Path="RelayOutputMask" Converter="{StaticResource ByteBit2Bool}" ConverterParameters="3,Binding Path=RelayOutputMask" Mode="TwoWay" />
</CheckBox.IsChecked>
</CheckBox>
<CheckBox Content="K5" Grid.Row="0" Grid.Column="4">
<CheckBox.IsChecked >
<local2:BcpBinding Path="RelayOutputMask" Converter="{StaticResource ByteBit2Bool}" ConverterParameters="4,Binding Path=RelayOutputMask" Mode="TwoWay" />
</CheckBox.IsChecked>
</CheckBox>
<CheckBox Content="K6" Grid.Row="0" Grid.Column="5">
<CheckBox.IsChecked >
<local2:BcpBinding Path="RelayOutputMask" Converter="{StaticResource ByteBit2Bool}" ConverterParameters="5,Binding Path=RelayOutputMask" Mode="TwoWay" />
</CheckBox.IsChecked>
</CheckBox>
<CheckBox Content="K7" Grid.Row="0" Grid.Column="6">
<CheckBox.IsChecked >
<local2:BcpBinding Path="RelayOutputMask" Converter="{StaticResource ByteBit2Bool}" ConverterParameters="6,Binding Path=RelayOutputMask" Mode="TwoWay" />
</CheckBox.IsChecked>
</CheckBox>
<CheckBox Content="K8" Grid.Row="0" Grid.Column="7">
<CheckBox.IsChecked >
<local2:BcpBinding Path="RelayOutputMask" Converter="{StaticResource ByteBit2Bool}" ConverterParameters="7,Binding Path=RelayOutputMask" Mode="TwoWay" />
</CheckBox.IsChecked>
</CheckBox>
I have tried to create style and set "Path", "Converter" and "Mode" properties, but Visual Studio says, that these are not DependencyProperties.
Any ideas?
Edit:
I realize that I can remove Grid.Row="0".
I'm using ByteBit2Bool converter from this project:
https://www.codeproject.com/Articles/475550/A-bit-of-binding-MVVMing-bytes-bits-based-data
I have developed a usercontrol, inside it has a canvas. I draw some lines and arcs in the canvas. Everytime when the datacontext changes, I need to force usercontrol's datacontext to null before updating new datacontext. Unless the new drawing is not getting updated. why is that? How to update Usercontrol's content (Actually canvas's content) without resetting the datacontext to null prior to update the new datacontext.
I use the following code. FlashControl is the usercontrol which contains canvas inside.
(FlashControl.Content as FrameworkElement).DataContext = null;
(FlashControl.Content as FrameworkElement).DataContext = this.DataContext;
FlashControl.DataContext = this.DataContext;
Update
::::::: This is my usercontrol
<UserControl x:Class="PricingRoutine.FlashGeneratorUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:Converters="clr-namespace:PricingRoutine.Converters"
xmlns:local ="clr-namespace:CustomFlashGenerator"
mc:Ignorable="d" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
<UserControl.Resources>
<Converters:TextPositionConverter x:Key="TextPositionConverter" />
<Converters:LinetPositionConverter x:Key="LinePositionConverter" />
<Converters:PointPositionConverter x:Key="PointPositionConverter" />
</UserControl.Resources>
<Grid x:Name="MajorGrid" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<ItemsControl ItemsSource="{Binding Path = CompositeObjectList}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<!--<ViewBox Stretch="Uniform">-->
<Canvas x:Name="MainCanvas" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ClipToBounds="False">
<Canvas.RenderTransformOrigin>
<Point X="0.5" Y="0.5" />
</Canvas.RenderTransformOrigin>
<Canvas.RenderTransform>
<TransformGroup>
<TranslateTransform X="0" Y="0" /> <!--Handle this one through binding-->
<ScaleTransform ScaleX="1" ScaleY="1" CenterX=".5" CenterY=".5" /> <!--Handle this one through binding-->
</TransformGroup>
</Canvas.RenderTransform>
</Canvas>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.Resources>
<DataTemplate DataType="{x:Type local:Line}">
<Line Stroke="Black" StrokeThickness="1">
<Line.X1>
<MultiBinding Converter="{StaticResource LinePositionConverter}" ConverterParameter="X1">
<Binding ElementName="MainCanvas" Path="ActualWidth" />
<Binding ElementName="MainCanvas" Path="ActualHeight" />
<Binding Path = "StartPoint.X" />
</MultiBinding>
</Line.X1>
<Line.Y1>
<MultiBinding Converter="{StaticResource LinePositionConverter}" ConverterParameter="Y1">
<Binding ElementName="MainCanvas" Path="ActualWidth" />
<Binding ElementName="MainCanvas" Path="ActualHeight" />
<Binding Path = "StartPoint.Y" />
</MultiBinding>
</Line.Y1>
<Line.X2>
<MultiBinding Converter="{StaticResource LinePositionConverter}" ConverterParameter="X2">
<Binding ElementName="MainCanvas" Path="ActualWidth" />
<Binding ElementName="MainCanvas" Path="ActualHeight" />
<Binding Path = "EndPoint.X" />
</MultiBinding>
</Line.X2>
<Line.Y2>
<MultiBinding Converter="{StaticResource LinePositionConverter}" ConverterParameter="Y2">
<Binding ElementName="MainCanvas" Path="ActualWidth" />
<Binding ElementName="MainCanvas" Path="ActualHeight" />
<Binding Path = "EndPoint.Y" />
</MultiBinding>
</Line.Y2>
</Line>
</DataTemplate>
</ItemsControl.Resources>
</ItemsControl>
</Grid>
</UserControl>
I have a ComboBox defined as below:
<ComboBox Width="200" Height="30" Grid.Column="0" x:Name="ExistingSpeciesComboBox"
ItemsSource="{Binding SpeciesColorCollection}" HorizontalAlignment="Left">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Rectangle Fill="{Binding Path=Brush}" Stroke="Black" StrokeThickness="1" Height="15" Width="30"/>
<w:WTextBlock Text="{Binding Name}" VerticalAlignment="Center"
Foreground="{StaticResource SmallControlForegroundBrush}"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
SpeciesColorCollection is an ObservableCollection of type ColorObject
Public Class ColorObject
Public Property Name As String
Public Property Brush As Brush
End Class
The ComboBox displays the items from the collection correctly but my problem is when I try to get the selected text from the ComboBox in a MultiBinding, I receive ColorObject instead of the name. How do I go about getting the value of the "Name" from within the WTextBlock of the ComboBox? The binding that I am using for my command is below. The converter is only returning strings.
<MultiBinding Converter="{StaticResource mySpeciesSetupConverter}">
<MultiBinding.Bindings>
<Binding ElementName="NewSpeciesName" Path="Text" />
<Binding ElementName="ExistingSpeciesComboBox" Path="Text" />
</MultiBinding.Bindings>
</MultiBinding>
<MultiBinding Converter="{StaticResource mySpeciesSetupConverter}">
<MultiBinding.Bindings>
<Binding ElementName="NewSpeciesName" Path="Text" />
<Binding ElementName="ExistingSpeciesComboBox" Path="SelectedItem.Name" />
</MultiBinding.Bindings>
</MultiBinding>
perhaps you can help me to solve this problem. I want to display a Text-Multibinding and an image in the header of my expander.
This is my simplified coding of the expander:
<Expander
x:Name="_myExpander">
<Expander.Header>
<MultiBinding
Converter="{StaticResource ExpanderHeaderConverter}">
<Binding
Path="Property1" />
<Binding
Path="Property2" />
<Binding
Path="Property3" />
</MultiBinding>
</Expander.Header>
<local:Content/>
</Expander>
How can I set an image in there?
thanks in advance!
Try this:
<Expander.Header>
<StackPanel Orientation="Horizontal">
<Image Source="{Binding ...}"/>
<TextBlock>
<TextBlock.Text>
<MultiBinding Converter="{StaticResource ExpanderHeaderConverter}">
<Binding Path="Property1" />
<Binding Path="Property2" />
<Binding Path="Property3" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</StackPanel>
</Expander.Header>
I have a ListView in my XAML and I am trying to hook up a MultiBinding Converter.
<ListView
Grid.Column="4"
Grid.Row="1"
Grid.RowSpan="5"
Margin="8,0,8,8"
HorizontalAlignment="Stretch"
Name="lvDisplayType"
ItemsSource="{Binding Path=Types}"
SelectedItem="{Binding Path=Current.Opt}"
VerticalAlignment="Stretch"
SelectionChanged="lvType_SelectionChanged"
SelectionMode="Single"
ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListView.ItemTemplate>
<DataTemplate>
<DockPanel
HorizontalAlignment="Center">
<TextBlock
Text="{Binding Path=., Converter={StaticResource DisplayConverter}}"
HorizontalAlignment="Center"
Padding="6"
VerticalAlignment="Center"
TextWrapping="Wrap">
<TextBlock.ToolTip>
<ToolTip DataContext="{Binding Path=Current}">
<MultiBinding Converter="{StaticResource OptConverter}">
<Binding Path="Opt" />
<Binding Path="Type" />
</MultiBinding>
</ToolTip>
</TextBlock.ToolTip>
</TextBlock>
</DockPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
The code not working is:
<TextBlock.ToolTip>
<ToolTip DataContext="{Binding Path=Current}">
<MultiBinding Converter="{StaticResource OptConverter}">
<Binding Path="Opt" />
<Binding Path="Type" />
</MultiBinding>
</ToolTip>
</TextBlock.ToolTip>
At present the Converter is returning an empty string as both 'values[0] == System.Windows.DependencyProperty.UnsetValue' and 'values[1] == System.Windows.DependencyProperty.UnsetValue' return true. These values are never set.
Because of the logical tree (I think) the TextBlock.ToolTip default binding is 'Current.Opt'. For the MultiBinding I also need to refer to 'Type' which is another property of 'Current'. So to get around this I have set 'ToolTip DataContext="{Binding Path=Current}"' - this isn't working as expected - what am I doing wrong?
I know I could do this easily in the Code behind, but we are employing MVVM, so would like to avoid it if possible.
Any help greatly appreciated!
Thank you
Try to do it in this way,
1.Does this give DependencyProperty.UnsetValue in the Converter? Otherwise, what is coming in to the converter?
<TextBlock.ToolTip>
<MultiBinding Converter="{StaticResource OptConverter}">
<Binding RelativeSource="{RelativeSource Self}" />
<Binding RelativeSource="{RelativeSource Self}" />
</MultiBinding>
</TextBlock.ToolTip>
2.Does this give DependencyProperty.UnsetValue in the Converter?
<TextBlock.ToolTip>
<MultiBinding Converter="{StaticResource OptConverter}">
<Binding RelativeSource="{RelativeSource Self}" Path="Current"/>
<Binding RelativeSource="{RelativeSource Self}" Path="Current"/>
</MultiBinding>
</TextBlock.ToolTip>