我正在Web User Controls
通过代码创建(我的C#代码写出标记,代码隐藏和设计器文件在回调中写入磁盘).控件创建得很好.我可以将它们添加到我的web项目中并将它们放在页面上.
当我尝试使用LoadControl(path)
它加载控件时说:
Unable to load type 'MyNameSpace.UseControlClass'
Run Code Online (Sandbox Code Playgroud)
这是因为尚未编译控件.
但我的要求是动态加载控件而不重新编译解决方案.
如何在创建控制文件时编译用户控件?因为这似乎是唯一的出路.
编辑: - 我的猜测是,由于文件尚未编译,因此不允许运行时加载.我试图使用CodeDom
编译器编译代码文件.喜欢:
var filePath = Server.MapPath(path);
var provider = CSharpCodeProvider.CreateProvider("C#");
var opts = new CompilerParameters(new[] { "mscorlib.dll", "System.Web.dll",
"Telerik.Web.Design.dll", "Telerik.Web.UI.dll",
"Telerik.Web.UI.Skins.dll", "MyCurrentDll.dll"});
opts.GenerateExecutable = false;
opts.GenerateInMemory = true;
var cr = provider.CompileAssemblyFromFile(opts, new string[] { filePath+".cs" });
Run Code Online (Sandbox Code Playgroud)
但是,抱怨cannot find metadata file Telerik.Web.Design.dll
等等.我不想硬编码Telerik的路径,因为它可能会在托管系统不同(虽然它是在bin
当前Web应用程序).也是MyCurrentDll.dll
我正在编译代码文件的文件的dll.我该如何解决这个问题?
我的想法是编译代码文件dll
动态创建并将其复制到Web应用程序的bin
目录.它可能会解决我最初提出的问题.
编辑2: - 在命中和试用后,我能够动态编译代码文件并生成dll
.即使在生成dll并将其放入bin …
我正在开发一个WPF项目,每次有些userControl活动或非活动时我都会尝试触发事件.
这些userControl在其中有许多其他控件.
我想这使用用户控件的事件来实现GotFocus
和LostFocus
,但这些事件不会在我需要的方式工作,因为用户控件失去焦点时,我与它的内部控制工作.
所以,我的问题是:有没有办法保存userControl,因为Active
当用户使用它内部的控件时,当用户转到另一个userControl时,第一个得到Inactive
???
先感谢您.
当我将ASP.NET项目部署到包含许多ASCX文件的服务器时,第一页加载可能需要一段时间,大概是因为正在编译ASCX文件.虽然只编译了页面上实际的那些,但部署过程的一部分是导航到网站上的一堆页面.导航完所有页面后,网站运行顺畅.
我希望ASP.NET在部署时立即编译所有这些ASCX文件,以删除这个草率部署步骤.
完成此任务的最佳方法是什么?
我使用了一个用户控件作为基类(我们称之为BaseUC),上面有3个标签(3行)(它们被设置为受保护).
还有另一个用户控件继承自它(InheritedUC).我在InheritedUC中添加了两个标签,它们位于基本标签之间(因此有5行).
一切都很好Visiual Studio的设计UI视图.但是当我运行应用程序时,BaseUC上的标签与InheritedUC中的标签重叠,我看不到继承控件上的标签.
有什么想法解决这个问题?非常感谢你
我创建了自己的复选框(UserControl).它有一个名为ControlSource的属性,它作为绑定源.但是,ControlSource的数据类型也是自定义类型.玩完之后,
...
[System.ComponentModel.Bindable(true), Browsable(true), Category("Behavior")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public IMyBool ControlSource
{
get { return this.chx.Checked ? IMyBool.True : IMyBool.False; }
set { this.chx.Checked = value.Value; }
}
...
Run Code Online (Sandbox Code Playgroud)
我在这里试过一个接口解决方案
public interface IMyBool
{
bool Value { get; set; }
IMyBool True { get; }
IMyBool False { get; }
}
public class MyBool
{
protected bool? _bValue = null;
protected string _sTrue = String.Empty;
protected string _sFalse = String.Empty;
protected string _sNull = String.Empty;
public MyBool(bool? bValue = null)
{
this._bValue …
Run Code Online (Sandbox Code Playgroud) 是否可以从另一个用户控件继承用户控件?
我想要实现的是从另一个用户控件继承的用户控件.所以我有baseusercontrol.ascx,这只是文本"Stuff".然后我有另一个用户控件,childusercontrol.ascx从baseusercontrol.ascx继承.如果我没有在childusercontrol.ascx中更改任何内容,我希望baseusercontrol.ascx文本显示"Stuff".
而且我应该能够扩展派生的基本用户控制功能.
我也试着像这样,但它在我的情况还不够.
现在我的childusercontrol.ascx看起来在下面
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="childusercontrol.ascx.cs" Inherits="test_childusercontrol" %>
<%@ Register src="baseusercontrol.ascx" tagname="baseusercontrol" tagprefix="uc1" %>
Run Code Online (Sandbox Code Playgroud)
childusercontrol.ascx.cs如下
public partial class test_childusercontrol : baseusercontrol
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
Run Code Online (Sandbox Code Playgroud)
当我浏览此页面时,我得到错误
Object reference not set to an instance of an object.
Description : An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. …
Run Code Online (Sandbox Code Playgroud) 我决定使用MVVM Light库来帮助设计UI.经过大量的研究和反复试验,我还没有找到我想要的答案.我用谷歌搜索并阅读了我能找到的每个StackOverflow问题,然而,我的问题似乎在SO上是独一无二的.
我希望设计一个带有单个窗口的UI,并使用不同的Views/UserControls填充它.我不想在UserControls中使用共享导航栏,也不想弹出多个窗口.每个View/UserControl都应绑定到自己的ViewModel,而MainWindow将绑定到MainViewModel.
示例场景 - 具有3个UserControl的MainWindow
1. MainWindow populates with first UserControl which has a listbox and 3 buttons, the first button is enabled.
2. User clicks the first button.
3. MainWindow populates with second UserControl.
Run Code Online (Sandbox Code Playgroud)
或者,另外
2. User selects choice from a listbox, button two and three become available.
3. User clicks second/third button.
4. MainWindow populates with second/third UserControl.
Run Code Online (Sandbox Code Playgroud)
等等
也许我的方法不现实,但我觉得这必须是可能的.我不明白如何让所有这些作品在概念上发挥作用.我的欲望绝不是独一无二的.如果您认为这是重复的问题,请重定向.干杯.
为了使事情更容易理解,我在下面列出了一些课程.首先,我的App.xaml.
<Application x:Class="Bobcat_BETA.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:views="clr-namespace:Bobcat_BETA.UserControls"
xmlns:vm="clr-namespace:Bobcat_BETA.ViewModels"
StartupUri="MainWindow.xaml"
mc:Ignorable="d">
<Application.Resources>
<vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" />
<DataTemplate …
Run Code Online (Sandbox Code Playgroud) 我编写了一个用户控件MenuItem,它继承自Form Label.
我有一个backgroundworker线程,其IsBusy属性通过MainForm中的属性公开为IsBackgroundBusy.
如何从MenuItem用户控件中读取此属性?我目前正在使用Application.UseWaitCursor,我在backgroundworker中设置它并且它完美地工作,但是我不希望光标改变.这就是为什么我认为我可以设置的房产会好得多.
这是我的MainForm中的代码:
public partial class MainForm : Form
{
public bool IsBackgroundBusy
{
get
{
return bwRefreshGalleries.IsBusy;
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的usercontrol的代码:
public partial class MenuItem: Label
{
private bool _disableIfBusy = false;
[Description("Change color if Application.UseWaitCursor is True")]
public bool DisableIfBusy
{
get
{
return _disableIfBusy;
}
set
{
_disableIfBusy = value;
}
}
public MenuItem()
{
InitializeComponent();
}
protected override void OnMouseEnter( EventArgs e )
{
if ( Application.UseWaitCursor && _disableIfBusy )
{
this.BackColor = SystemColors.ControlDark;
} …
Run Code Online (Sandbox Code Playgroud) 我正在尝试制作具有可绑定属性的示例WPF用户控件(也许最好说“开发人员控件”)。我的代码包含以下文件:
----- MainWindow.xaml -----
<Window x:Class="Test_Binding.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:testBinding="clr-namespace:Test_Binding"
Title="MainWindow" Height="350" Width="525">
<StackPanel>
<testBinding:MyLabelledTextBox x:Name="MLTB" LabelText="My custom control: MyLabelledTextBox" Text="{Binding StringData, Mode=OneWay}" />
</StackPanel>
</Window>
----- MainWindow.xaml.cs -----
using System.Windows;
namespace Test_Binding
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
this.DataContext = new MyDataObject();
this.InitializeComponent();
}
}
}
----- MyDataObject.cs -----
using System.Runtime.CompilerServices; // CallerMemberName
using System.ComponentModel; // INotifyPropertyChanged
namespace Test_Binding
{
public class MyDataObject : INotifyPropertyChanged
{ …
Run Code Online (Sandbox Code Playgroud) 我正在通过扩展来构建自定义控件ScrollableControl
.
问题是我的自定义控件充当容器 - 我可以将控件拖入其中:
我的问题是如何在扩展的类中禁用容器功能 ScrollableControl
下面是两个测试控件,一个扩展Control
,第二个ScrollableControl
public class ControlBasedControl : Control
{
protected override Size DefaultSize
{
get { return new Size(100, 100); }
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.FillRectangle(Brushes.LightCoral, ClientRectangle);
}
}
public class ScrollableControlBasedControl : ScrollableControl
{
public ScrollableControlBasedControl()
{
AutoScrollMinSize = new Size(200, 200);
}
protected override Size DefaultSize
{
get { return new Size(100, 100); }
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.FillRectangle(Brushes.LawnGreen, ClientRectangle);
} …
Run Code Online (Sandbox Code Playgroud) user-controls ×10
c# ×7
winforms ×4
asp.net ×3
inheritance ×2
wpf ×2
xaml ×2
.net ×1
binding ×1
focus ×1
mvvm ×1
mvvm-light ×1