AutoCompleteBox does not render correctly - c#

I have an autoCompleteBox in my wpf window and I set ValidatesOnDataErrors binding property to True for selectedItem property of autoCompleteBox control.
When I show my wpf window by clicking on a ribbon Button, Validation Area of autocompletbox does not render correctly.
like the picture below:
but when I show window by clicking on a standard Wpf button it work correctly
like the picture below:
for more info I create and attached a sample source code:
sample of my problem
can anyone help me ?
Thanks.

You're seeing both the custom error UI defined in the AutoCompleteBox's control template and the standard error template in the adorner. You should disable the latter:
<Style TargetType="{x:Type sysctrls:AutoCompleteBox}">
<Setter Property="Validation.ErrorTemplate" Value="{x:Null}" />
</Style>

Related

Determine if ListBoxItem is currently on screen

I have a ListBox using a Panel as its ItemsPanel
What I would like to do is load the bytes for an image into the bound property in the view model for each ListBoxItem that is currently on screen, and unload the bytes when they are scrolled off screen.
I have tried Panel.OnVisualChildrenChanged. This tells me when items are added or removed to the panel, but doesn't seem to help my specific case.
I have tried
<Style TargetType="{x:Type ListBoxItem}">
<EventSetter Event="RequestBringIntoView" Handler="EventSetter_OnHandler" />
</Style>
That event never seems to fire. edit: fires when item is selected
I have also gotten a reference to the ListBox ScrollViewer to look at the VerticalOffset and Viewport.Height/Width but I don't see how that information helps me.

WPF - Need to enable scrolling in a disabled DataGrid

My DataGrid columns are being added in code behind.
When the user is done editing rows and clicks on a Next button, DataGrid is disabled and user is taken to the next step which is in the same view..
The problem arises if user has a lot of rows and needs to scroll over the now disabled DataGrid to overview the rows.
I've tried wrapping the DataGrid (which is bound to a property that sets IsEnabled = false when user clicks on Next) in a ScrollViewer which gives me the desired effect but the scroll is then located outside the DataGrid which I find annoying.
I'm at my wits end and could really use some help how I should go about doing this.
I've also tried overriding the metadata for ScrollViewer which works somewhat but is unsafe from what I've read.
Any ideas?
Instead of using the IsEnabled property you can use the DataGrid.IsReadOnly property.
Mark the DataGrid as ReadOnly and apply the following style to get the appearance like disabled (if required).
<DataGrid.Style>
<Style TargetType="DataGrid">
<Style.Triggers>
<Trigger Property ="IsReadOnly" Value="True">
<Setter Property= "Foreground" Value="Gray"/>
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.Style>
I ended up using the IsReadOnly property on the DataGrid and bound it to IsEnabled.
This was an apparent problem at first because IsEnabled was true making the DataGrid read-only in the wrong state.
So I created a helper class to convert the bool to false to reflect the correct states (enabled/disabled).
The components in the DataGrid have their IsEnabled property databound also which gives me the proper disabled styles for them when DataGrid is read-only.
Thanks for the help guys!

How to align text to center with custom font-family applied to Textbox in winRT XAML app

I am working on winRT C# app. I have Textbox with custom font-family. Due to custom font-family my text in Textbox is aligned to top of Textbox. I tried to set VerticalContentAlignment to "center" but it still not working.
I'm not so sure it's because of your font, and more likely expected behavior of the TextBox. I would take a look at the control template for your TextBox and check your Setter's and ContentPresenter to see if there isn't a property set to make it that way. Otherwise I think you can touch it via something like;
<TextBox>
<TextBox.Resources>
<Style TargetType="TextBlock">
<Setter Property="VerticalAlignment" Value="Center"/>
</Style>
</TextBox.Resources>
</TextBox>

How to Target all Textbox's within a Groupbox on a Window - WPF

I am trying to setup a windows.resoruces style that targets all textbox's within all groupbox's (so it would not target textbox's that are not found within a groupbox)
I know I could use the x:key field, but was wondering if there was a way to target certain controls within controls for an entire window or application?
You could try a nested style for your TextBoxes in Style.Resources of GroupBox with Style.TargetType but without x:key.
<Style TargetType="GroupBox">
<Style.Resources>
<Style TargetType="TextBox">
...
</Style>
</Style.Resources>
</Style>
One trick you could use is to define Textbox style without the x:key field. This one will apply to all the TextBoxes that do not have a Style specified.
Use this Style for the TextBoxes within the GroupBoxes by not using the Style Tag on these Boxes and for all other TextBoxes use a specific named Style by using the Style tag...

WPF ComboBox Item tabbing behaviour

I am migrating some win forms panels to WPF.
In WinForms, you can tab into to the combo box using the keyboard, select an item by typing the first character and then hit tab again and the combo to lose focus.
In WPF the second tab will move the focus rectangle down the list, instead of moving onto the next control.
Is there a way to get the old behavior? Or has anyone implemented an ItemTemplate that achieves this behvaiour?
thanks
There is a ComboBoxItem which has an IsTabStop property.
So I just applied the appropriate style:
<Style TargetType="{x:Type ComboBoxItem}">
<Setter Property="IsTabStop" Value="False"/>
</Style>

Categories

Resources