I dont want to use DataGrid in my scenario, I want to use ListView.
Currently I invented solution described below, but in my solution I must join bussines logic and UI logic in data source calss . The second problem is that I calculate column width using not very good method.
So I dont like this solution. If anyone can find solution where business logic and UI logic arent joind please show me it.
Mu current solution:
In DataSource class I added property: double NameColumnWidth {get; set} = 100.
Next I bind this property to TextBox: <TextBox Width="{x:Bind NameColumnWidth, Mode=OneWay}"
Next after loading data to ItemsSource I use two iterations. First finds the widest column and next one sets this width to all data items.
Next x:Bind transfers column widths to UI.
double nameColumnWidth = 100;
foreach (var sar in dataSourceList)
{
double nameWidth = sar.Name.Length * 5;
if (NameWidth > 100 && NameWidth < 250)
nameColumnWidth = nameWidth;
else
nameColumnWidth = 250;
}
if (nameColumnWidth > 100)
{
foreach (var sar in dataSourceList)
{
if (nameColumnWidth != 100)
sar.NameColumnWidth = nameColumnWidth;
}
}