ContextMenu设置为Null,如何在XAML中做到这一点? [英] ContextMenu Set Null , how to do it in XAML?

查看:66
本文介绍了ContextMenu设置为Null,如何在XAML中做到这一点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不想显示放置在DataGrid中的TextBox的默认菜单.

在代码中我可以那样做

I want to not to show the defualt menu of TextBox which placed in DataGrid.

in code I can do that like that

TextBox.ContextMenu =Null;



但是放在DataGrid单元中的TextBox是Tamplate.像这样的xaml代码;



but my TextBox which placed in DataGrid Cell is Tamplate,. xaml code like that;

<DataGridTemplateColumn  >
          <DataGridTemplateColumn.CellTemplate >
               <DataTemplate>
                   <StackPanel>
                         <TextBox>  
                                             TextWrapping="Wrap"
                                             IsReadOnly="False"
                                             ContextMenu="{x:Null}"
                         </TextBox>
                     </StackPanel>
                 </DataTemplate>
             </DataGridTemplateColumn.CellTemplate>
         </DataGridTemplateColumn>



我尝试了这段代码,但没有用.


因此,如何在Xaml中将Textbox的ContextMenu设置为Null?
另外,我想知道在这种情况下如何将我的ContextMenu添加到TextBox中以及后面的代码以及xaml中的代码?

谁能告诉我?告诉我相关的文章和信息?



I tried this code, but it does''t work .


so, how can I set Textbox''s ContextMenu to Null in Xaml?
also, I want to know how can I add my ContextMenu to TextBox in this case with code behind as well as in xaml?

could anyone tell me ? tell me relative article and info?

thanks in advance!

推荐答案

阿里姆扬,
那应该可以,但是看起来您的xaml中有语法错误:

Hi Alimjan,
That should work, but it looks like you have a syntax error in your xaml:

<TextBox>
                TextWrapping="Wrap"
                IsReadOnly="False"
                ContextMenu="{x:Null}"
</TextBox>



它应该是:



it shall be:

<TextBox

                TextWrapping="Wrap"

                IsReadOnly="False"

                ContextMenu="{x:Null}">
</TextBox>


这篇关于ContextMenu设置为Null,如何在XAML中做到这一点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆