user-controls

ASP.NET: Getting markup for .ascx

时光毁灭记忆、已成空白 提交于 2019-12-24 07:08:09
问题 Let's say I have an a .ascx user control. How do I get its HTML markup into a string? 回答1: Once you use the LoadControl() method to get it into a page, you can can get the HTML by calling the Render() method on it. It requires an HtmlTextWriter to write to, but it's fairly straightforward to construct: var userControl = (userControlType)Page.LoadControl( ....ascx); StringBuilder sb = new StringBuilder(); StringWriter SW = new StringWriter(SB); HtmlTextWriter htw = new HtmlTextWriter(new

Forward mouse scroll event from child UserControl to parent

夙愿已清 提交于 2019-12-24 06:49:10
问题 I want to forward the mouse scroll event from a control to its direct parent (which is also UserControl in my case). How is this possible? Edit The control is added to a control that is scrollable. Like a memo-edit for example. When the user scrolls in the memo-control, the memo-control is scrolled (!) But when the user scrolls on top of the custom control the event is not forwared to the parent control and the memo-control does not scroll. 来源: https://stackoverflow.com/questions/10041923

WPF binding user control with data in C# code

前提是你 提交于 2019-12-24 06:39:03
问题 I've create user control like this: public partial class View { public View() { InitializeComponent(); } public static DependencyProperty NameProperty = DependencyProperty.Register("Name", typeof(string), typeof(TeaserView) ); public string Name { get { return (string)GetValue(NameProperty); } set { SetValue(NameProperty, value); } } } XAML: <UserControl x:Class="Controls.View" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006

Passing in content to ASP.NET user control

瘦欲@ 提交于 2019-12-24 06:30:11
问题 I have a UserControl named BreadCrumb. I would like to pass in information to this user control like so (Similar to DropDownList items): <uc:BreadCrumb runat="server" id="HeaderBreadCrumb"> <AddLevel Name="Home" Url="~/Default.aspx" /> <AddLevel Name="About Us" Url="~/AboutUs.aspx" /> </uc:BreadCrumb> Thanks to any help! 回答1: Please take a look here How to: Create an ASP.NET User Control and here Implementing Custom UserControl with ListItem collection. These approaches doesn't uses templates

User control with custom properties

做~自己de王妃 提交于 2019-12-24 05:04:52
问题 I'm trying to create a UserControl which is a legend of a graph item, I've defined it so it has a label with the graph name, a check box which define whether we show it or not and a rectangle with the graph color. The xaml is defined like this: <UserControl x:Class="Resources.LegendItem" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http:/

Winforms: Add a close “x” button in a UserControl

好久不见. 提交于 2019-12-24 03:09:34
问题 I need to add a close "x" button in the upper left corner of a UserControl. I'd like that button have similar style as a usual Winforms close button (Blue in XP style, etc). Is it possible to do such a thing? 回答1: Here's an example of how to make a simulated button. It does so on the form itself, but works the same on a custom control. It also shows how to get the "fancy" button style using a VisualStyleRenderer in case the ControlPaint style is too "old". Updated After six edits, I think I'm

Winforms: Add a close “x” button in a UserControl

笑着哭i 提交于 2019-12-24 03:09:10
问题 I need to add a close "x" button in the upper left corner of a UserControl. I'd like that button have similar style as a usual Winforms close button (Blue in XP style, etc). Is it possible to do such a thing? 回答1: Here's an example of how to make a simulated button. It does so on the form itself, but works the same on a custom control. It also shows how to get the "fancy" button style using a VisualStyleRenderer in case the ControlPaint style is too "old". Updated After six edits, I think I'm

Initial DataGrid Sorting

北城以北 提交于 2019-12-24 02:58:04
问题 I have a user control that contains a WPF toolkit DataGrid . This control is used in many different places in my app. The grid has no knowledge as to the type of data that will show. Is there a way to initially sort the grid by the first column in ascending order no matter what data the grid is populated with? I don't think I can use a CollectionViewSource because I don't know the PropertyName of the property bound to the first column. 回答1: You could hook to an event: dataGrid

How to know when a UserControl is no longer used (no Close event)

五迷三道 提交于 2019-12-24 02:37:14
问题 I'm using UserControl s inside a WinForm to display data. I'm also using the command pattern so that the UserControl registers a (weak) event and does stuff when the command is triggered. On a WinForm I can unregister the events in the Close event. However there's no such event on a UserControl . I hooked up the events I thought would be fired when the UserControl is no longer in the display stack but could find nothing useful. To get by I check if the Parent is null and that worked for most

UserControl BringIntoView() not working properly

旧城冷巷雨未停 提交于 2019-12-24 02:34:11
问题 Background: I have a usercontrol defined in a ScrollViewer along with a ContentControl , the ContentControl will be visible all the time, and within it there is a Button , when the button is clicked will set the usercontrol to Visible , and when the usercontrol shows ( Visiblility="Visible" ) I want it to be scrolled into the view. I have XAML <ScrollViewer VerticalScrollBarVisibility="Auto" MaxHeight="465"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="*" /> <RowDefinition Height="*" /