我是WPF的新手,我遇到了从用户控件继承的问题.
我创建了一个用户控件,现在我需要继承该控件并添加更多功能.
以前有人做过这种事吗?任何帮助将不胜感激.
谢谢
我目前正在开发一个需要ACL的网站,因为我使用Zend,我使用他们的ACL类是有道理的,但我对如何做到这一点几乎没有任何想法.我已经阅读了文档,但它让我更加困惑...基本上我想要做的就是设置两个用户组,例如"normal"和"admin",普通用户可以访问所有具有非管理员控制器的页面admin显然可以访问管理控制器页面.
我有很多问题:
如果你引导我访问一个网站或一个很好的教程,我将非常感激.
正如主题所要求的那样.
编辑1
在处理请求以便在用户控件中存储对父页面的引用时,有时可能会这样吗?
.NET WinForms中的Control和UserControl有什么区别?我想创建一个自定义控件,但我应该继承哪一个?我过去总是使用Control而没有任何问题,但这是创建自定义控件的"推荐"方式吗?
我是WPF的新手.
目前我正在为名为"LabeledTextbox"的表单元素进行usercontrol,其中包含标签,文本框和错误消息的文本块.
当使用代码添加错误消息时,我想将文本框的边框设置为红色.但是,当错误消息被删除时,我想回到文本框的默认边框颜色.我觉得必须有一个非常简单的方法来做到这一点.
我的代码:
(在公共部分类LabeledTextbox:UserControl中)
public string ErrorMessage
{
set
{
if (string.IsNullOrEmpty(value))
{
_textbox.BorderBrush = Brushes.Black; //How do I revert to the original color in the most elegant way?
}
else
{
_textbox.BorderBrush = Brushes.Red;
}
_errorMessage.Text = value;
}
}
Run Code Online (Sandbox Code Playgroud) 窗口和用户控件之间有区别吗?在我看来,这两者完全相同.那么我应该使用哪一个?何时使用?(我试过谷歌搜索这句话,我找不到任何东西)
示例以逗号分隔的同一组合框中显示所选项目.
但是当我尝试在wpfform中使用Usercontrol时,我得到了这个异常
System.Windows.Markup.XamlParseException was unhandled
Message=Provide value on 'System.Windows.Markup.StaticResourceHolder' threw an exception.
Source=PresentationFramework
LineNumber=0
LinePosition=0
StackTrace:
at System.Windows.Markup.XamlReader.RewrapException(Exception e, Uri baseUri)
at System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlReader templateReader, XamlObjectWriter currentWriter)
at System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlObjectWriter objectWriter)
at System.Windows.FrameworkTemplate.LoadOptimizedTemplateContent(DependencyObject container, IComponentConnector componentConnector, IStyleConnector styleConnector, List`1 affectedChildren, UncommonField`1 templatedNonFeChildrenField)
at System.Windows.FrameworkTemplate.LoadContent(DependencyObject container, List`1 affectedChildren)
at System.Windows.StyleHelper.ApplyTemplateContent(UncommonField`1 dataField, DependencyObject container, FrameworkElementFactory templateRoot, Int32 lastChildIndex, HybridDictionary childIndexFromChildID, FrameworkTemplate frameworkTemplate)
at System.Windows.FrameworkTemplate.ApplyTemplateContent(UncommonField`1 templateDataField, FrameworkElement container)
at System.Windows.FrameworkElement.ApplyTemplate()
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint) …Run Code Online (Sandbox Code Playgroud) 我有一个aspx,里面有一个ascx.从简短的测试中我看到aspx的PageLoad在用户控件的PageLoad之前被调用,但OnInit则相反.
有人知道事件的顺序是什么(页面与其中的用户控件相比)
谢谢
在Winforms的C#.Net中,我在几乎所有组件中发现了两个事件,Resize()和SizeChanged().它们之间有什么区别吗?如果两个事件都相同,那么为什么C#提供了两个不同的事件?
我在C#中创建一个用户控件.此控件包含一个文本框.我想在用户更改控件的大小时调整文本框的大小.我很困惑我应该使用哪个事件以及为什么?
我有一个非常有线的错误,我的一个自定义控件似乎是创建两个编译文件,当我尝试动态加载它LoadControl()只是失败因为无法将一个转换为另一个 - 即使它们完全相同.我写的消息看到的一切都是一样的,只是改变了编译过的dll.
System.Web.HttpUnhandledException (0x80004005):
Exception of type 'System.Web.HttpUnhandledException' was thrown. --->
System.InvalidCastException:
[A]ASP.Modules_OneProduct_MedioumImage cannot be cast to
[B]ASP.Modules_OneProduct_MedioumImage.
Type A originates from 'App_Web_kg4bazz1, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'
in the context 'Default'
at location 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\80ed7513\10eb08d9\App_Web_kg4bazz1.dll'.
Type B originates from 'App_Web_oneproduct_mediumimage.ascx.d1003923.4xoxco7b, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'
in the context 'Default'
at location 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\80ed7513\10eb08d9\App_Web_oneproduct_mediumimage.ascx.d1003923.4xoxco7b.dll'.
Run Code Online (Sandbox Code Playgroud)
在我完全按照MSDN上的内容编写后,这就是现在的代码:
foreach (int OneProductID in TheProductIdArrays)
{
// here is the throw.
ASP.Modules_OneProduct_MedioumImage OneProduct =
(ASP.Modules_OneProduct_MedioumImage)LoadControl(@"~/mod/OneProduct_MediumImage.ascx");
// do some work with
//OneProduct …Run Code Online (Sandbox Code Playgroud) c# asp.net compiler-construction user-controls dynamic-compilation