-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Alias for Grid‘s RowDefinition and ColumnDefinition #2844
Comments
Looks like a dup of #166 ? |
NO the #166 just want to use a quick method to define columns and rows but when the column or rows definition changed such as
to
the column of "InnerGrid" from Grid.Column="1" to Grid.Column="2" most of the elements should changed the properties. but using the aliases these modifies are unnecessary. |
You can already give a name to columns/rows like you can give to any other element, so why invent a new attribute |
I believe you replied without reading my question. I want to know the alias could be added to the grid so the other elements can used it such as the an Attached Property like Grid.Column. then when we insert a new row or new column we needn't modify the property but use Grid.Column or Grid.Row will need to changed the property |
I believe you replied without understanding my response. I said there's already a way to name rows/columns, via 'Name' property, so why does it need to have two names? In other words, why should I have to type |
@weltkante Do you mean that: we can use the
I very much agree with this view |
hahahaha , I don't know how to express my idea. but thank lindexi . yes that my mean |
@TruePluto How about this code: <Grid>
<Grid.RowDefinitions>
<RowDefinition local:GridExtensions.Name="R0" />
<RowDefinition local:GridExtensions.Name="R1" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition local:GridExtensions.Name="C1" />
</Grid.ColumnDefinitions>
<TextBlock local:GridExtensions.RowName="R1" local:GridExtensions.ColumnName="C1" Text="12" />
</Grid> The GridExtensions is: public class GridExtensions
{
public static readonly DependencyProperty NameProperty = DependencyProperty.RegisterAttached(
"Name", typeof(string), typeof(GridExtensions), new PropertyMetadata(default(string)));
public static void SetName(DependencyObject element, string value)
{
element.SetValue(NameProperty, value);
}
public static string GetName(DependencyObject element)
{
return (string) element.GetValue(NameProperty);
}
public static readonly DependencyProperty RowNameProperty = DependencyProperty.RegisterAttached(
"RowName", typeof(string), typeof(GridExtensions),
new PropertyMetadata(default(string), RowName_PropertyChanged));
private static void RowName_PropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is FrameworkElement frameworkElement)
{
if (e.NewValue is string rowName)
{
if (string.IsNullOrEmpty(rowName))
{
return;
}
if (frameworkElement.Parent is Grid grid)
{
for (var i = 0; i < grid.RowDefinitions.Count; i++)
{
var gridRowDefinition = grid.RowDefinitions[i];
var gridRowName = GetName(gridRowDefinition);
if (!string.IsNullOrEmpty(gridRowName) &&
gridRowName.Equals(rowName, StringComparison.Ordinal))
{
Grid.SetRow(frameworkElement, i);
return;
}
}
}
else
{
throw new ArgumentException("xxxxxxxxxxxxxx");
}
}
}
}
public static void SetRowName(DependencyObject element, string value)
{
element.SetValue(RowNameProperty, value);
}
public static string GetRowName(DependencyObject element)
{
return (string) element.GetValue(RowNameProperty);
}
public static readonly DependencyProperty ColumnNameProperty = DependencyProperty.RegisterAttached(
"ColumnName", typeof(string), typeof(GridExtensions),
new PropertyMetadata(default(string), ColumnName_PropertyChanged));
private static void ColumnName_PropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is FrameworkElement frameworkElement)
{
if (e.NewValue is string columnName)
{
if (string.IsNullOrEmpty(columnName))
{
return;
}
if (frameworkElement.Parent is Grid grid)
{
for (var i = 0; i < grid.ColumnDefinitions.Count; i++)
{
var gridColumnDefinition = grid.ColumnDefinitions[i];
var gridColumnName = GetName(gridColumnDefinition);
if (!string.IsNullOrEmpty(gridColumnName) &&
gridColumnName.Equals(columnName, StringComparison.Ordinal))
{
Grid.SetColumn(frameworkElement, i);
return;
}
}
}
else
{
throw new ArgumentException("xxxxxxxxxxxxxxxxx");
}
}
}
}
public static void SetColumnName(DependencyObject element, string value)
{
element.SetValue(ColumnNameProperty, value);
}
public static string GetColumnName(DependencyObject element)
{
return (string) element.GetValue(ColumnNameProperty);
}
} See https://github.com/lindexi/lindexi_gd/tree/00e0d126/JurgekebowhawiNofeerileji |
I brought it to HandyControl |
This probably needs to take into account when row/column collections and their names are manipulated at runtime. Another way to do this currently might be through a markup extension. |
I don't know if there is a way to make a alias for Grid‘s cell. But I want to how to implement the following feature:
so when I Change the OuterGrid' columns defintion or rows difinition I don’t need to change the InnerGrid's properties of Grid.Column or Grid.Row
Thank you for your attention
The text was updated successfully, but these errors were encountered: