TextBox not same as PasswordBox at UI - wpf

I am using MaterialDesignInXAML from NuGet, my code is as follows:
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBox Background="Red" Grid.Column="0" materialDesign:HintAssist.FloatingScale="1" materialDesign:HintAssist.FloatingOffset="0,-25" materialDesign:HintAssist.IsFloating="True" materialDesign:HintAssist.Hint="User Name"/>
<PasswordBox Background="Red" Grid.Column="1" materialDesign:HintAssist.FloatingScale="1" materialDesign:HintAssist.FloatingOffset="0,-25" materialDesign:HintAssist.IsFloating="True" materialDesign:HintAssist.Hint="Password"/>
</Grid>
but in the view it looks different:
Same code for TextBox and PasswordBox, but different results, my question is how can make the TextBox and passwordbox to look the same, (I want to keep using the material design part)

When you say 'to look the same', are you saying your want the red background of the passwordbox to match the red background of the textbox? Or the other way around?
Either way, the problem is that the MaterialDesignInXaml library control templates for the TextBox and PasswordBox controls are slightly different. The element within those templates that bind to the Background property are not the same.
You could always modify their template for the PasswordBox to meet your needs:
https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/blob/master/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.PasswordBox.xaml
Look at where the {TemplateBinding Background} is set, and take it from there.
If you strongly feel they should match in terms of styling, then why not raise an Issue on their GitHub site?

Related

Why doesn't Border.BorderBrush binding to TextBox.BorderBrush always work?

I'm creating a custom UserControl, and part of it involves placing a Border on top of a TextBox. I'd like the Border.BorderBrush to always match that of the TextBox.BorderBrush.
You'd think this would work:
<TextBox x:Name="MyTextBox" />
<Border
BorderThickness="2"
BorderBrush="{Binding BorderBrush, ElementName=MyTextBox}"
/>
Yet when the TextBox.BorderBrush changes based on whether it's focused, the Border.BorderBrush is not updated accordingly. By the way, I'm using custom styling on the controls.

Why does WP7 ListPicker have different margins and height to TextBox

I have a page in my WP7 app consisting of a TextBox beside a ListPicker. In their default modes, they don't line up properly; the ListPicker has a different padding to the TextBox, and its height is also different.
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<StackPanel Orientation="Horizontal">
<TextBox HorizontalAlignment="Left" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top"/>
<toolkit:ListPicker Width="170" ItemsSource="{Binding l}" Style="{StaticResource ListPickerStyle1}" VerticalAlignment="Top"/>
</StackPanel>
</Grid>
Manually tweaking the ListPicker's template to fit in correctly here is tricky and error prone. For example, when its height is adjusted, the caption (i.e. the text of the selected item) is no longer in the centre of the component.
My app is currently failing MS app review because the components are not all the same height.
Is there an easy way for me to set the toolkit:ListPicker to have the same appearance as a TextBox?
The simplest solution will be to take a copy of the the default style and tweak that using Blend to be exactly how you want it to look. This will take a little trial and error to sort out.
You can then use the implicit styling rules to apply it to all ListPickers without having to explicitly set the style on each instance:
<Style x:Key="MyListPickerStyle
TargetType="toolkit:ListPicker>
.... your tweaks here
</Style>
<Style TargetType="toolkit:ListPicker"
BasedOn="{StaticResource MyListPickerStyle}" />
It may be easier to tweak the TextBox Style of course :)

Silverlight: TextBox VerticalContentAlignment="Center"

I'm trying to vertically center the content of a TextBox with the VerticalContentAlignment property but it seems to have no effect at all. The text stays at the top. Can anyone tell me how to do this?
Here's my code:
<TextBox Grid.Column="1"
Grid.Row="0"
Width="200"
Height="28"
VerticalAlignment="Center"
VerticalContentAlignment="Center" />
It is possible to make the TextBox center its text vertically. However, that does require you to reapply its ControlTemplate.
To do this:
Copy the Style and the ControlTemplate from the TextBox Styles and Templates page on MSDN to a suitable <UserControl.Resources> element. (This ControlTemplate is actually for a validation tooltip; the ControlTemplate we'll change is within the Style.)
Find the ScrollViewer element within the Style for the TextBox, and add a VerticalAlignment="Center" property to it.
Alternatively, you could add the property
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
to the ScrollViewer. This should allow you to set the vertical alignment of the contents of your TextBoxes using the VerticalContentAlignment property.
You can follow much the same approach if you wish to change the horizontal alignment of a TextBox's content as well.
The XAML code is correct, the following should be sufficient:
<TextBlock Text="Centered Text" VerticalAlignment="Center" />
Can you try that code outside your grid?
Check the attributes you defined on your Grid, this will probably cause the behaviour you have. Can you post the complete XAML code?

WPF ListView that supports inline edit?

Is there a open source WPF control that looks like ListView and supports inline edit? More specifically, a cell in the ListView should be editable when you double click on it, and the edit result should be automatically saved unless you hit ESC afterwards.
I don't know of any WPF controls that do what you are looking for, but that is not indication that they don't exist. If you checkout the WPF Toolkit on Codeplex, you may find something and there are a lot of OSS projects for WPF controls on Codeplex in addition to the toolkit.
You can create one very easily taking advantage of the WPF content control model. Here is an example of a ListBox with a set of controls used to represent the objects bound to the list.
<ListBox x:Name="sampleListBox"
Width="500">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<GridRowDefinitions>
<RowDefinition Height="25"/>
<RowDefinition Height="25"/>
</GridRowDefinitions>
<TextBox Grid.Row="0" Source="{Binding EditableProperty1}}"/>
<TextBox Grid.Row="1" Source="{Binding EditableProperty2}"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
You can control the editability of the controls with Styles so that when the ListBox item is selected, the internal controls are editable but otherwise, they are not. I don't have access to my work laptop atm so I can't provide a style example but there are a lot of materials on the web that can help you. And if you have Expression Blend 4, it has a lot of functionality that can really help you when you are styling your own controls.

Silverlight Border object not visible when theme applied?

I have a applied one of the Silverlight Toolkit themes to my XAML page, and now for some reason my Border objects don't show up. Is this by design? I've made sure to explicitly state a BorderBrush color that should contrast the theme background, but this does not fix the issue.
In case it helps, the theme I'm using is the BureauBlack theme from the Silverlight Toolkit.
And here is a code snippet of one of my Borders.
<Border VerticalAlignment="Top" Grid.Column="0" Grid.Row="2" Grid.RowSpan="2" BorderBrush="Orange" CornerRadius="10" Margin="0" Height="300">
<StackPanel>
<TextBlock Text="Status Panel" FontSize="20" TextAlignment="Center" />
...
</StackPanel>
</Border>
It looks like when a theme is loaded it loads its own default set of values for most object properties. In this case, the BorderThickness property of the border object defaults to 0. As a result you don't see it.
By explicitly giving the BorderThickness property a value (non-zero ofcourse), I got my border to show up.
In addition, I can recommend Silverlight Spy tool.
One of the feature of Silverlight Spy is to provide a tree of all controls, to display all their properties and to provide an ability to dynamically change them. It greatly decrease time for such problem resolving.
I've used it several times in cases like your.

Resources