2017-05-31 108 views
0

我們正在構建一個WPF kiosk應用程序。 我們需要禁用CUT COPY PASTE和右鍵點擊如何禁用剪切,複製粘貼並右鍵單擊所有WPF表單

請問這怎麼辦?

這SO後沒有給出任何形式的集中解決方案:

How to suppress Cut, Copy and Paste Operations in TextBox in WPF?

+0

難道只是你想禁用的所有東西或者所有的ContextMenu項目?順便說一句'WPF'中沒有任何形式,使用'Windows'和'Controls'。 – XAMlMAX

回答

1

您需要在您的App.xaml添加Style您在其中定義:

<Style TargetType="TextBox"> 
<!-- OR --> 
<Style TargetType="{x:Type TextBox}"> 
    <Setter Property="ContextMenu" Value="{x:Null}"/> 
</Style> 

但這會僅適用於不在DataTemplate中的項目。
UPDATE:
App.xaml

<Application x:Class="TestApp.App" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:local="clr-namespace:TestApp" 
     StartupUri="MainWindow.xaml"> 
<Application.Resources> 
    <Style TargetType="{x:Type TextBox}"> 
     <Setter Property="ContextMenu" Value="{x:Null}"/> 
    </Style> 
</Application.Resources> 


這裏是MainWindow.xaml

<Window x:Class="TestApp.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xml:lang="en-GB" 
    xmlns:local="clr-namespace:TestApp" 
    xmlns:converter="clr-namespace:TestApp.Converters" 
    mc:Ignorable="d" 
    Height="478.889" Width="903.889"> 
<Grid> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="0.3*"/> 
     <ColumnDefinition/> 
    </Grid.ColumnDefinitions> 
    <StackPanel> 
     <TextBox Name="txtBx" MinHeight="150" 
       VerticalAlignment="Top" AutoWordSelection="True" 
       MaxLines="10" 
       TextWrapping="WrapWithOverflow" 
       SelectionChanged="txtBx_TextHighlighted" 
       ToolTip="{x:Null}" 
       Margin="10"/> 

    </StackPanel> 
</Grid> 


如果你右鍵點擊TextBox你不會有任何ContextMenu提供給您。
更新2:
從我們的聊天繼續,TextBox被引用其他樣式這是壓倒一切的,無論我們在App.xaml設置。由於外部樣式在App.xaml之後加載。

+0

這不起作用 –

+0

因此,你有'DataTemplates'中的'TextBoxes',或者你的應用不在'WPF'中,並且它在'UWP'中? @CharlesOkwuagwu – XAMlMAX

+0

它是wpf,不,我不使用DataTemplates –

相關問題