I'm trying to add the validation and get the following from the compiler.
The property 'ValidatesOnException' was not found in type 'Binding'.
The property 'ValidatesOnException' does not exist on the type 'Binding' in the XML namespace 'http://schemas.microsoft.com/winfx/2006/xaml/presentation'.
I tried adding System.Windows.Data in System.Windows as a xmlns but no luck.
The following are my attempts at the markup.
<TextBox x:Name="Office" Style="{StaticResource PhoneNumber}">
<TextBox.Text>
<Binding Path="Office" Mode="TwoWay" NotifyOnValidationError="true" ValidatesOnException="true" Converter="{StaticResource PhoneNumberConverter}" />
</TextBox.Text>
</TextBox>
<TextBox x:Name="Office" Style="{StaticResource PhoneNumber}" Text="{Binding Office, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnException=true, Converter={StaticResource PhoneNumberConverter}}" />
Any ideas?
The property is not called ValidatesOnException it is called ValidatesOnExceptions note the plural.
Related
I am trying to set the IsEnabled property of a button using multibinding, because this property depends on three variables.
If I would set the content propery, I could use this code:
<Button Height="23" HorizontalAlignment="Left" Margin="629,49,0,0" Name="btnMyButton" VerticalAlignment="Top" Width="75">
<Button.Content>
<MultiBinding Converter="{StaticResource myMultiValueConverter}">
<Binding ElementName="MyElement"/>
<Binding />
</MultiBinding>
</Button.Content>
</Button>
I try to use this code:
<Button Height="23" HorizontalAlignment="Left" Margin="629,49,0,0" Name="btnMyButton" VerticalAlignment="Top" Width="75">
<Button.IsEnabled>
<?????
But in this case, although the Button.IsEnabled is avaliable, in the next line I can't find the Multibinding keyword, so I can't use multibinding with the IsEnabled property.
why? Is there any way to set the IsEnabled property with a multivalue converter?
Thanks.
The syntax should be the exact same as what you have for Button.Content - just replace "Content" with "IsEnabled".
<Button.IsEnabled>
<MultiBinding Converter="{StaticResource myMultiValueConverter}">
<Binding ... />
<Binding ... />
<Binding ... />
</MultiBinding>
</Button.IsEnabled>
It might not auto-complete for you because the IsEnabled property expects a boolean value, not a MultiBinding object, but it shouldn't give you any errors, and will compile and execute just fine.
(It auto-completes for Button.Content because the Content property is of type object, which includes a MultiBinding object)
I want to bind TextBox's Tag (which is inside a DataGrid), to validation rule's CurrentLegStrategy property (which is a DependencyProperty). Although I've done something similar with Deal dependency property using a global tunnel object, however not able to figure out, what would be the tunnel for CurrentLegStrategy (ideally should be coming from the bound data to DataRow or to the bound data to TextBox's tag)?
<DataTemplate x:Key="PremiumProp">
<TextBlock Style="{StaticResource TextBlockLeft}" Tag="{Binding Strategy}" x:Name="txtPremiumProp">
<TextBlock.Text>
<Binding Path="AbsolutePremium" StringFormat="{}{0:#,##0.00####}" Converter="{StaticResource _DoubleConvertor}">
<Binding.ValidationRules>
<Control:MBSStrategyBasedDoubleValidation ValidatesOnTargetUpdated="True" ValidationTag="premabs"
ErrorMessage="Please enter a valid positive (+) premium (also check the reference which is required for auto calculation)!">
<Control:MBSStrategyBasedDoubleValidation.Deal>
<Control:DealObject Deal="{Binding Tag, Source={StaticResource TradeTunnel}}" CurrentLegStrategy="{Binding Path=Tag, ElementName=txtPremiumProp}"/>
</Control:MBSStrategyBasedDoubleValidation.Deal>
</Control:MBSStrategyBasedDoubleValidation>
</Binding.ValidationRules>
</Binding>
</TextBlock.Text>
</TextBlock>
</DataTemplate>
Then I also tried,
<TextBlock.Resources>
<ResourceDictionary>
<FrameworkElement x:Name="strategySource" Tag="{Binding Tag, Source={x:Reference txtPremiumProp}}"/>
</ResourceDictionary>
</TextBlock.Resources>
With the following:
CurrentLegStrategy="{Binding Path=Tag, Source={StaticResource strategySource}}"
Cannot find resource named 'strategySource'. Resource names are case sensitive.
I have to convert TextBox XAML to PasswordBox XAML. The main problem is <TextBox.Text>.
Any clue how it can be done?
Thank you!
<TextBox Grid.Column="1" Grid.Row="1" Height="23" HorizontalAlignment="Left" Name="tbxPassword" VerticalAlignment="Top" Width="277">
<TextBox.Text>
<Binding Path="Password" Source="{StaticResource ods}" UpdateSourceTrigger="PropertyChanged" >
<Binding.ValidationRules>
<c:ConfigValidationRule />
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
If its really about password, you should use PasswordBox, Binding it to a dependency property would cause security vulnerabilities.
<PasswordBox
Name="pwdBox"
MaxLength="64"
PasswordChar="#"
PasswordChanged="PasswordChangedHandler"
/>
You can see the basic usage here
Password Box
I have the following textbox that have a propertychanged in the viewmodel.
When I insert the Binding.ValidationRules and I insert some wrong value, it doesn't trigger the propertychanged event and I don't understand why. Any help?
<TextBox Name="RiskCode" HorizontalAlignment="Left" Margin="101.923,8,0,81" TextWrapping="Wrap" Width="56.077" MaxLength="6" Validation.ErrorTemplate="{StaticResource validationTemplate}"
Style="{StaticResource textBoxInError}">
<TextBox.Text>
<Binding Path="RiskCode" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<vm:RiskCodeValidation/>
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
Use ValidationStep.
http://msdn.microsoft.com/en-us/library/system.windows.controls.validationrule.validationstep.aspx
RawProposedValue - Runs the ValidationRule before any conversion occurs.
ConvertedProposedValue - Runs the ValidationRule after the value is converted.
UpdatedValue - Runs the ValidationRule after the source is updated.
CommittedValue - Runs the ValidationRule after the value has been committed to the source.
By default, it's RawProposedValue, which prevents the binding to source from ever occurring - hence your confusion. Use a different option instead:
<Binding.ValidationRules>
<vm:RiskCodeValidation ValidationStep="UpdatedValue" />
</Binding.ValidationRules>
I have TextBox bound to a text property in my window with a validation rule (length is = 4). I needed to add filtering so I took ThomasLebruns WPFDeveloperTools FilteredTextBox. That works but when I use the control I specify each time the Validation.ErrorTemplate and the Binding.ValidationRules - I want to build those into the FilteredTextBox control so they apply automatically to every FilteredTextBox - how to manage that?
Currently I have to:
<Window>
<Grid>
<ps:FilteredTextBox x:Name="textboxPanId" Type="Hex" Grid.Column="1" Grid.Row="1" Height="35" Margin="0,2,0,2" MaxLength="4"
Validation.ErrorTemplate="{StaticResource TextBoxErrorTemplate}">
<TextBox.Text>
<Binding Path="pan_id" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<ps:PanIdValidation />
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</ps:FilteredTextBox>
I would like just:
<ps:FilteredTextBox x:Name="textboxPanId" Type="Hex" Grid.Column="1" Grid.Row="1" Height="35" Margin="0,2,0,2" MaxLength="4">
<TextBox.Text>
<Binding Path="pan_id" UpdateSourceTrigger="PropertyChanged"/>
</TextBox.Text>
but have the error template and validation rule applied. How to move the setting of the Validation.ErrorTemplate and Binding.ValidationRule into resource dictionary with rest of FilteredTextBox xaml?.
<ResourceDictionary>
<ControlTemplate x:Key="TextBoxErrorTemplate">
...
</ControlTemplate>
I think if you create a style for FilteredTextBox in your ResourceDictionary you can set these there, but at least the ErrorTemplate for almost sure.