XAML: Can I refer to a Grid row or column by name? -


If I name each row and column in the grid, can I set the grid of the control .row = "Row_Top"? I have defined StaticResources to refer to this but without the resource there is no converter or any other way to accomplish it?

As far as I know there is no built-in method to do this ... nevertheless , You can use the markup extension to retrieve the column from a row or its name: [MarkupExtensionReturnType (typeof (int))] Public Intangible Class GridBandExtensionBase: MarkupExtension {Public Override Object ProvideValue (! IServiceProvider ServiceProvider) {if (ServiceProvider = null) {var Target = serviceProvider.GetService (typeof (IProvideValueTarget)) as IProvideValueTarget; If (target! = Null) {var obj = target.TargetObject as a dependency object; If (obj! = Null) {var grid = VisualTreeHelper.GetParent (obj) as grid; If (grid! = Null) {return GetBandIndex (grid); }}}} Return 0; } Protected summary Ink gateband index (grid grid); } Public Square GridRowExtension: GridBandExtensionBase {Public GridRowExtension () {} Public GridRowExtension (string queue name) {this.RowName = rowName; } [Constructor agreement ("row name")] public string row name {get; Set; } Protected Override integer {if (grid.RowDefinitions [i] for GetBandIndex (System.Windows.Controls.Grid Grid) {{int i = 0; I & lt; grid.RowDefinitions.Count; i ++} .Name = = RowName) {return i; }} Return 0; }} Public class GridColumnExtension: GridBandExtensionBase {public GridColumnExtension () {} Public GridColumnExtension (string columnName) {this.ColumnName = columnName; } [Constructor agreement ("columnName")] Public string columnname {get; Set; } Protected Override integer {if (grid.ColumnDefinitions [i] for GetBandIndex (System.Windows.Controls.Grid Grid) {{int i = 0; I & lt; grid.ColumnDefinitions.Count; i ++} .Name = = ColumnName) {return i; }} Return 0; }}

You can use these extensions as:

    Note:  If you compile these markup extensions in the same assembly as your application, the designer will not be able to call the console with a parameter (but it will work fine in sequence ). This is a Microsoft that is not intended to fix if you want to work it on design time, put the markup extension in a separate assembly, or explicitly specify RowName / ColumnName properties:  
  & lt; Button grid Line = "{My: gridro row name = Row_Top}" grid. Column = "{my: grid column columnname = column _right}" content = "hello world" />  

Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -