visual-studio-lightswitch - 根据下拉列表值显示/隐藏控件

标签 visual-studio-lightswitch

我有一个正在开发的应用程序,需要根据下拉列表中的选定值显示/隐藏控件。默认情况下,大多数控件将被隐藏,当从控制设备控件中选择一个值(“VFD”)时,隐藏的控件将变为可见。

我有一个名为 MCCLoads 的实体,它与驱动下拉列表的所有其他实体都有关系。

我要应用此功能的屏幕名为 MCCLoadsSetListDetail

我正在尝试使用这段代码,但我不确定这是否是正确的方法

public void MCCLoadsSetListDetail_SelectionChanged()
    {
        this.FindControl("CTRL_DEVICE").IsEnabled = true;

        if (this.MCCLoadsSetListDetail.SelectedItem.Loads_CTRL_Device == "VFD")
        {
            this.FindControl("Line_Reactor_IMP").IsVisible = false;
        }
    }

MCC Loads Form MCC Loads Table with relationships

提前致谢, 杰森

最佳答案

在屏幕的 Created 方法中订阅 ControlAvailable 事件。当它被触发时,您可以将 Silverlight 控件转换为 Windows 控件以订阅 SelectionChanged 事件。然后您可以根据需要对此做出回应...

partial void YourScreen_Created()
{
    this.FindControl("YourDropDown").ControlAvailable += new EventHandler<ControlAvailableEventArgs>(YourDropDown_ControlAvailable);
}

void YourDropDown_ControlAvailable(object sender, ControlAvailableEventArgs e)
{
    var ctrl = e.Control as AutoCompleteBox;
    ctrl.SelectionChanged += new SelectionChangedEventHandler(ctrl_SelectionChanged);
}

void ctrl_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    dynamic selectedItem = (sender as AutoCompleteBox).SelectedItem;
    if (selectedItem == null)
    {
        return;
    }

    // Your logic goes here....
    this.FindControl("CTRL_DEVICE").IsEnabled = true;
    if (selectedItem.StringValue == "VFD")
    {
        this.FindControl("Line_Reactor_IMP").IsVisible = false;
    }
}

希望这有助于...

关于visual-studio-lightswitch - 根据下拉列表值显示/隐藏控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8452681/

相关文章:

visual-studio-lightswitch - 在 Light Switch 中进行验证时比较旧值与新值

visual-studio-lightswitch - VS LightSwitch 调试无法加载数据

mysql - LightSwitch + MySQL 错误 : Nested Transactions are not supported

visual-studio-2013 - 通过命令行发布 lightswitch 应用程序不起作用

visual-studio - 如何在 Visual Studio 2012 LightSwitch 中创建自定义菜单/导航屏幕?

wcf-ria-services - LightSwitch 与 WCF RIA

javascript - LightSwitch 通过延迟渲染重新设计自定义控件的问题

visual-studio-2013 - 如何在 LightSwitch 中自定义全局导航菜单 - Visual Studio 2013

silverlight - LightSwitch 'Microsoft-LightSwitch-Security-ServerGenerated-Implementation-AuthenticationService.svc' 不存在

html - 在 Lightswitch HTML 屏幕中按下 "saved successfully"后,如何返回 "Save"消息框和/或发送收据电子邮件?