silverlight validation on textbox inside usercontrol - silverlight

As the title states, I have a usercontrol with a textbox inside. The purpose of the user control is to add a spell check button and character count below the textbox. But for the most part, I'm using it just like a normal textbox:
<controls:SuperTextBox Text="{Binding Accomplishments, Mode=TwoWay, ValidatesOnNotifyDataErrors=True,NotifyOnValidationError=True}"
Height="200" EnableCharacterCounting="True" EnableSpellChecking="True" AcceptsReturn="True"
TextWrapping="Wrap" />
The problem I'm having is that I no longer get the nice red border when validation fails for the field. What do I need to do to reenable that behavior?

What you need to do here, it's to relay the validation of your UserControl back to the textbox.
I did answer a similar question here.

Related

TextBox to TextBox on the fly data binding

There are two TextBox on the WPF page. While user is typing into the first TextBox, the second TextBox must display modified text from the first TextBox. As a result both values must be binded to a view model.
Can it be done with Data Binding?
I was able to get the second TextBox display text from the first one implementing DependencyProperty on my view model. But I don't have the slightest idea how to apply transformation on the fly.
Maybe there is an easy way to achieve this?
Just use databinding with UpdateSourceTrigger set to PropertyChanged:
<TextBox x:Name='txt1' Text="{Binding MyText, UpdateSourceTrigger=PropertyChanged}" />
<TextBox x:Name='txt2' Text="{Binding MyText, UpdateSourceTrigger=PropertyChanged}" />
In this case it will update ViewModel's property on the fly instead of waiting for FocusLost.

Binding ribbon text box IsEnabled to checkbox IsChecked not working

Here is the sample XAML:
...
<ribbon:RibbonTab Header="MyTab">
<ribbon:RibbonGroup Header="Blah">
<ribbon:RibbonTextBox x:Name="MyTextBox"
IsEnabled="{Binding IsChecked, ElementName=MyCheckBox}" />
<ribbon:RibbonCheckBox x:Name="MyCheckBox" Label="some text" />
</ribbon:RibbonGroup>
</ribbon:RibbonTab>
...
For some reason, the text box stays disabled regardless of whether or not the check box is checked. Why is the binding not working properly?
You can add the above code minus the elipses at the top and bottom to a boiler plate WPF ribbon project and see if you can figure out what's wrong. I see no binding error diagnostics, for example.
Update: If a regular TextBox is substituted for the RibbonTextBox, the behavior becomes correct. I conclude that there must be some issue with binding the IsEnabled property of a RibbonTextBox.
Freaky update #2: Creating a basic RibbonTextBox and setting its IsEnabled property to True creates a disabled RibbonTextBox. What gives?
I have submitted a bug report on Microsoft Connect to further pursue this issue.
Final update: It's fixed in WPF 4.5.
As a wild guess, have you tried fully qualifying the property?
IsEnabled="{Binding RibbonCheckBox.IsChecked, ElementName=MyCheckBox}"
... or maybe even...
IsEnabled="{Binding CheckBox.IsChecked, ElementName=MyCheckBox}"

TextBox Partially Editable

Is it possible to make the contents of a TextBox or a RichTextBox parially editable? For instance, I would like to have something that looks like the following:
<TextBox TextWrapping="Wrap" AcceptsReturn="True" VerticalScrollBarVisibility="Auto" FontFamily="Courier New" Margin="10,0">
This text and anything before it isn't editable.
This Text is Editable
This text and anything after it is not editable.
</TextBox>
or something like this:
<RichTextBox AcceptsReturn="True" VerticalScrollBarVisibility="Auto" FontFamily="Courier New" Margin="10,0">
<FlowDocument>
<Paragraph>This text and anything before it is not editable.</Paragraph>
<Paragraph>This text is editable.</Paragraph>
<Paragraph>This text and anything after it is not editable.</Paragraph>
</FlowDocument>
</RichTextBox>
Ideally, I would be able to style the editable text different than the uneditable text. Before anybody tells me I shouldn't do this, I have a valid reason for doing it.
Thanks in advance.
You should be able to encapsulate the three controls into a scrollable region and resize your editable field as needed (i.e., the editable field has no scrolling, only the containing region).
It's not very pretty, especially if there isn't an easy way of doing it with XAML (I've never used it, so I can't say), but I would content it's far better than trying to hack this thing into (Rich)TextBox.
A textBox with its Template overrriden to hide its border and 2 textblocks of same look and feel put ahead and post the textbox in that Template can achieve what you seek.
Default textbox template which you can override is here...

WPF Toolkit MaskTextBox Binding Issue

I have a simple control that has a masked text box:
xmlns:extToolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit/extended"
...
<extToolkit:MaskedTextBox Mask="000-000-000" Text="{Binding SerialNumber, UpdateSourceTrigger=PropertyChanged}" />
I also have a key binding on the control:
<UserControl.InputBindings>
<KeyBinding Command="{Binding SearchCommand}" Gesture="Enter" />
</UserControl.InputBindings>
The problem is when SearchCommand is executed I need the value they entered in the masked text box as the criteria for the search. With a regular text box this is no problem but apparently the MaskedTextBox control doesn't play well with PropertyChanged UpdateSourceTrigger.
If I click someplace else (so it looses focus) and then press enter it works, but obviously I don't want to have to do that. Are there any good workarounds for this situation?
You must bind your property to the Value property not the Text.
http://wpftoolkit.codeplex.com/wikipage?title=MaskedTextBox&referringTitle=Documentation

How do I create a silverlight editable listbox?

My DataTemplate for my ListBox has a TextBlock in it. If I click on the TextBlock, I want it to change to a TextBox so I can edit it. Is there a good way to do this?
You may get some ideas here: Tim heuer's editable ListBox
You should be able to use two-way binding of the text. Then, any edits to the Text dependency property for the item should be reflected back to the original data object.
In your DataTemplate, you probably have something like
<TextBox Text="{Binding}" />
Could you try making this
<TextBox Text="{Binding Mode=TwoWay}" />
Unfortunately I am on a machine without the Silverlight SDK on it at the moment, so I can't verify if my syntax is correct on the binding.

Resources