如果任何 Grid/UserControl 子项具有焦点,如何通过 XAML 代码设置 Panel.Zindex 值 [英] How to set Panel.Zindex value though XAML code if any of the Grid/UserControl children having the focus

查看:15
本文介绍了如果任何 Grid/UserControl 子项具有焦点,如何通过 XAML 代码设置 Panel.Zindex 值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我没有正确解释.所以我刚刚编辑了之前的帖子.

I think I have not explained correctly. So i have just edited the previous post.

请仔细阅读我的确切要求

Please go through my exact requirement

我有一个按钮的用户控制.如果按钮通过样式渲染获得焦点,我已经编写了用于放大按钮的代码.

I have user control with a button. I have written code to enlarge the button if it gets focus through rendering in style.

在我的窗口中,在主网格中,我放置了此用户控件的 10 个实例(每个单元格 1 个控件,总共 2 行和 5 列).

In my window, in the main grid i have placed 10 instances of this user control ( 1 control per cell, totally 2 rows and 5 columns).

现在,如果我将焦点保持在第一个用户控件按钮上,它会在获得焦点时正确扩展,并且用户控件也会随按钮一起扩展,但扩展的用户控件会进入第二行用户控件.因为当我将焦点设置在按钮上时,用户控件 IsFocused 仍然是 False

Now, if i keep the focus on the first user control button, it expands correctly as it gets focus and also user control expands along with button but the expanded user control goes inside 2nd row user control. Because when i set the focus on the button user control IsFocused is still False

我已经在窗口资源中编写了以下代码,但它对我没有帮助.(用户控件名称为ucButtonControl)

I have writtend the following code in the window resources, but it doesn't help me. (user control name is ucButtonControl)

希望现在要求非常明确.如果对此有任何澄清,请告诉我.

Hope the requirements is very clear now. If any clarification on this then please let me know.

推荐答案

开始吧(注意:为了更容易演示,我使用了 Canvas 而不是 Grid):

Here ya go (Note: I used a Canvas instead of Grid for easier demonstration):

<Canvas>
    <Canvas.Resources>
        <Style TargetType="{x:Type Button}">
            <Style.Triggers>
                <Trigger Property="IsFocused" Value="True">
                    <Setter Property="Panel.ZIndex" Value="999"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </Canvas.Resources>
    <Button Background="Red" Width="100">Red</Button>
    <Button Background="White" Width="100" Margin="5">White</Button>
    <Button Background="Blue" Width="100" Margin="10">Blue</Button>
    <Button Background="Green" Width="100" Margin="15">Green</Button>
</Canvas>

这篇关于如果任何 Grid/UserControl 子项具有焦点,如何通过 XAML 代码设置 Panel.Zindex 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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