每当我尝试以编程方式移动焦点时,焦点视觉(虚线矩形)不会显示。
可以采取什么措施来强制显示此视觉效果?
<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" Loaded="OnLoaded">
<StackPanel>
<TextBlock x:Name="a" Focusable="True">A</TextBlock>
<TextBlock Focusable="True">B</TextBlock>
<Button Focusable="False" Click="OnClick">Move Focus</Button>
</StackPanel>
</Window>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void OnLoaded(object sender, RoutedEventArgs e)
{
Keyboard.Focus(a);
}
private void OnClick(object sender, RoutedEventArgs e)
{
var request = new TraversalRequest(FocusNavigationDirection.Next);
var elementWithFocus = Keyboard.FocusedElement as UIElement;
if (elementWithFocus != null)
elementWithFocus.MoveFocus(request);
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个自定义控件,其DependencyProperty类型ObservableCollection绑定到observableCollection:
<MyControl MyCollectionProperty = {Binding MyObservableCollection} ...
Run Code Online (Sandbox Code Playgroud)
问题是添加到MyObservableCollection不更新MyCollectionProperty.
我需要完全替换它MyObservableCollection以使其工作,例如
MyObservableCollection = null;
MyObservableCollection = new ObservableCollection(){...}
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法来处理这个?
编辑:
public ObservableCollection<string> Columns
{
get { return (ObservableCollection<string>)GetValue(ColumnsProperty); }
set { SetValue(ColumnsProperty, value); }
}
public static readonly DependencyProperty ColumnsProperty =
DependencyProperty.Register("Columns", typeof(ObservableCollection<string>), typeof(MyControl),
new PropertyMetadata(new ObservableCollection<string>(), OnChanged));
Run Code Online (Sandbox Code Playgroud) c# data-binding wpf dependency-properties observablecollection
Microsoft Visual Studio Enterprise 2019 版本 16.5.4
我每天多次收到此错误,而且频率似乎在增加。
StreamJsonRpc.ConnectionLostException :与远程方的 JSON-RPC 连接在请求完成之前丢失。在异步 StreamJsonRpc.JsonRpc.InvokeCoreAsync() 在异步 StreamJsonRpc.JsonRpc.InvokeCoreAsync[TResult]() 在异步 Microsoft.CodeAnalysis.Remote.RemoteEndPoint.InvokeAsync[T]()
似乎没有什么可以触发,例如我 VS 可以闲置,错误就会发生。