Jeżeli użytkownik wprowadza dane do kontrolki UWP właściwość BorderBrush jest nie zmieniana. Kiedy jednak edytuje jej zawartość z poziomu kodu po zmianie wartości obramowanie znika.
Czy jest możliwość wyłączenia lub nadpisania tego zachowania?
XAML:
<!-- Przykładowe kontrolki w których występuje problem -->
<TextBox Name="DescriptionCtrl"
Style="{StaticResource TextBoxStyle}"
Grid.Row="1" Grid.Column="1"
TextChanged="TextCtrl_TextChanged" />
<ComboBox Name="CategoryCtrl"
Style="{StaticResource ComboBoxStyle}"
Grid.Row="2" Grid.Column="1"
ItemsSource="{x:Bind categories}"
SelectionChanged="ComboBoxCtrl_SelectionChanged" />
<!-- fragment pliku ze stylami -->
<Style TargetType="TextBox" x:Key="TextBoxStyle">
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="Width" Value="300" />
<Setter Property="TextAlignment" Value="Center" />
</Style>
<Style TargetType="ComboBox" x:Key="ComboBoxStyle">
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="Width" Value="300" />
</Style>
C#:
public MyPage()
{
//fragment:
defaultBorderColor = AutoSuggestBoxCtrl.BorderBrush;
}
private void NameCtrl_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args)
{
StoreProduct product = args.SelectedItem as StoreProduct;
DescriptionCtrl.Text = product.Description;
Category category = FindCategory(product);
CategoryCtrl.SelectedItem = category;
Manufacturer manufacturer = FindManufacturer(product);
ManufacturerCtrl.SelectedItem = manufacturer;
PriceCtrl.Text = product.Price.ToString();
QuantityCtrl.Text = product.Quantity.ToString();
}
private void TextCtrl_TextChanged(object sender, TextChangedEventArgs e)
{
TextBox textCtrl = sender as TextBox;
textCtrl.BorderBrush = defaultBorderColor;
}
Przed:
Po: