2016-05-30 79 views

回答

0

據我所知在UWP中沒有相應的功能。可能的解決方案之一可能是使用某些圖像來突出顯示選擇。下面是示例代碼:

XAML:

<Border BorderThickness="2" BorderBrush="{ThemeResource TextBoxBorderThemeBrush}" Height="164" Width="684"> 
    <TextBox x:Name="textBox" TextWrapping="Wrap" Text="TextBox" BorderThickness="0,0,0,0"/> 
</Border> 

C#:

private async void TextBox_SelectionChanged(object sender, RoutedEventArgs e) 
    { 
     // clear background    
     textBox.Background = new SolidColorBrush(Windows.UI.Color.FromArgb(255, 255, 255, 255)); ; 

     // render image 
     RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap(); 
     await renderTargetBitmap.RenderAsync(textBox); 

     // set background 
     textBox.Background = new ImageBrush() 
     { 
      ImageSource = renderTargetBitmap 
     }; 
    } 

聚焦: enter image description here

未聚焦: enter image description here

P.S.我正在更新SelectionChanged事件的背景,但實際上您可以在該事件上創建圖像並只在LostFocus事件上更新。它應該更有效率。