简体   繁体   English

如何在用户控件(c#)中公开图像的可见属性?

[英]How do I expose the visible property of an image inside a user control (c#)?

Problem: 问题:

A control that shows each user which quizzes they have passed out of a possible four. 一个控件,显示每个用户在可能的四个测验中通过了哪些测验。

My solution: 我的解决方案:

Create user control that lists the name of the quizzes and has a checkmark at the end of each quiz name that I would like to make visible when they pass a quiz. 创建一个列出测验名称并在每个测验名称末尾都有一个复选标记的用户控件,我希望它们在通过测验时可见。

The actual user control is inside of my master page. 实际的用户控件在我的母版页中。

From reading other posts, I understand that I need to make the image.visible property public in the control code behind. 通过阅读其他文章,我了解到我需要在后面的控制代码中将image.visible属性公开。 I have tried this several ways and haven't had much luck. 我已经尝试了几种方法,但运气还不太好。

So how do I expose the .visible property of an image inside of my user control? 那么,如何在用户控件中公开图像的.visible属性?

Thanks for any advice. 感谢您的任何建议。

Try something like this: 尝试这样的事情:

public Boolean ImageIsVisible
{
    set { this.yourImage.Visible = value; }
    get { return this.yourImage.Visible; }
}

hree ways I can think of... 我能想到的三种方式...

In the USER control, just set the image as public instead of default - private, but that exposes ALL the elements. 在USER控件中,只需将图像设置为public而不是默认图像即可-private,但这会公开所有元素。

Another is to create a property at the user control level that passes on to the ex: 另一个方法是在用户控件级别创建一个属性,该属性将传递给ex:

public Boolean ImgVisible
{
  get { return this.YourImageControl.Visible; }
  set { this.YourImageControl.Visible = value; }
}

Or, just create as a function in your user control... 或者,只需在用户控件中创建一个函数即可...

public void ImgVisible( Boolean ShowIt )
{
  this.YourImageControl.Visible = ShowIt;
}

Sorry, missed part about Master Page... As a web control, as long as control is visible from the IDE (visual designer) of your form, you can refer to it directly in the CONTROL's code-behind partial class definition by the explicit name reference... 抱歉,缺少有关母版页的部分...作为Web控件,只要可以从表单的IDE(可视设计器)中看到控件,您就可以直接在CONTROL的代码隐藏部分类定义中直接引用它。名称参考...

public Boolean ImgVisible
{
   get { return ImgControl.Visible; }
   set { ImgControl.Visible = value; }
}

I'm having a problem accessing this on the content page. 我在内容页面上访问此文件时遇到问题。 Is this right? 这是正确的吗?

  1. I went to codebehind on control and added the following property: 我在控件上转到了代码隐藏,并添加了以下属性:

    public Boolean ImgVisible { get { return this.imgModule1Passed.Visible; } set { this. imgModule1Passed.Visible = value; } }

  2. on the content page code behind, I am using the following: 在后面的内容页面代码上,我正在使用以下代码:

UserControl control = (usercontrol)this.Page.Master.FindControl("QuizzesPassed1");

Shouldn't I be able to find the property by: 我不应该通过以下方式找到该物业:

Control.ImgVisible Control.ImgVisible

?

I can't seem to find the control at all. 我似乎根本找不到控件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM