|
Not much about 10.000 rows
But the data is not the problem cause i use backgroundworker to load,the freezing ui when show window that i feel not smooth
|
|
|
|
|
Yeah, you DO NOT load controls with 10,000 records. No user on this planet will put up with scrolling through that much data to find what they want.
There's you're problem.
|
|
|
|
|
but they can search using keyboard,i mean like using combobox then populate all product. so i need to load all the record first.
isn't that right?
|
|
|
|
|
No, it's not.
You take the characters typed in the textbox to have the database return the top 25 to 50 or so records that match the typed characters and populate the dropdown with just those results.
|
|
|
|
|
if i do like that, then every time user typed in textbox,its need to open connection to the server and search the matching text and user needs to tab to search again in dropdownlist.
i think this is not effective... cause it will have problem if the connection is not stable
thx for your suggestion
|
|
|
|
|
Yeah, and that's the only method that's really going to work for you. Pre-loading the control with tens of thousands of records takes time. There is no way to speed it up and the problem only gets worse with more and more data over time.
You have no choice but to filter the records some how.
|
|
|
|
|
I usually launch a few ASYNC data loads on my app's startup. Often these are user controls loaded with serialized data (xml) from a previous session.
The collections loaded are usually Observable collections.
Then when the "host" list view, etc. is loaded via a page, window or uc, the data sources are connected; even while the async load might be running.
Nothing wrong with your pattern: it's what mostly drives UWP (async).
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
thank you, i think your method is more efficient..
|
|
|
|
|
Listen to Dave, take the first 2-3 (I usually use 3) characters from the user to filter the query to the database, I have found that 3 characters almost always reduces the data load to a manageable volume.
I use a textbox and a button so the user enters a filter and then clicks the button, there is no doubt the result is a filter view of the data. The idea of loading 10k records is ludicrous.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
10k record i think is not too much,if i load it in async only takes about 2-3 second.
then the user can search it locally.
if i use textbox and button.it will always reconnect to server for the query.it will slower the input
process...
thx
|
|
|
|
|
I do text to voice "transliteration" in real-time using 4 dictionaries at the same time; the largest of which has 80,000 entries (English).
The load times are inconsequential. One can't generalize.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
so it loads 80k entries at startup n create local xml?
then the user will have search time based on hardware processor
|
|
|
|
|
The dictionaries are the one case re: generalizations about "record counts".
The Xml refers to the case where users create "object graphs"; serializing / deserializing graphs as xml is simpler that writing / reading a bunch of related records. The end results is the same: collections of data (for data templating), or data and uc's for more complex list views.
And I do "virtualization" when necessary: I may have 20,000 (data) records loaded, but since I know my "view port size" and "position", I can create controls on the fly as the user is scrolling (async again). The performance depends on "preloading" because the user can also hyperlink with no lag.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Then the loading is not done a separate thread, or the synchronization isn't done well. Dave has a point, you don't show 10k records in a dropdown, as the scrolling would be awful. You have a point that for a fast tekst search, you preload it - it's not like it's a lot of data.
There's some differences between WinForms and WPF, so can't help there; but I'd not be reporting progress with constants that indicate little; I'd be counting items and updating the progressbar every 250ms.
It's a shortcut to give "partial" progress with constants, and it smells.
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Hi Team,
I want my window to be closed like SHAPE animation in PowerPoint. I have written below code but it's not working like SHAPE animation present in Microsoft PowerPoint. It is going from outer to inner but in rectangle shape. I have to keep Outer to inner behavior but with SHAPE animation.
Below is the code I have created:
MainWindow.XAML
<Window.RenderTransform>
<TransformGroup>
<ScaleTransform x:Name="rectScale"/>
</TransformGroup>
</Window.RenderTransform>
<Window.Resources>
and in .cs file
DoubleAnimation scale_x = new DoubleAnimation()
{
From = 1,
To = 0,
Duration = TimeSpan.FromSeconds(5),
};
DoubleAnimation scale_y = new DoubleAnimation()
{
From = 1,
To = 0,
Duration = TimeSpan.FromSeconds(5),
};
DoubleAnimation center_x = new DoubleAnimation()
{
From = 400,
To = 400,
Duration = TimeSpan.FromSeconds(5),
};
DoubleAnimation center_y = new DoubleAnimation()
{
From = 300,
To = 300,
Duration = TimeSpan.FromSeconds(5),
};
rectScale.BeginAnimation(ScaleTransform.ScaleXProperty, scale_x);
rectScale.BeginAnimation(ScaleTransform.ScaleYProperty, scale_y);
rectScale.BeginAnimation(ScaleTransform.CenterXProperty, center_x);
rectScale.BeginAnimation(ScaleTransform.CenterYProperty, center_y);
Can someone please guide where I am missing and how can I make it working.
Thanks
|
|
|
|
|
I am making a table, using a grid, with one large left column, and to the right, four (or possibly more) check boxes / radio buttons, each in a quite narrow grid column. There is not enough room to label each of the CBs/RBs on every line, so I put the label in the top row, rotated 270 degrees as a vertical text, in a tall (100 units) but narrow (27 units) cell, just enough to hold the longest label.
My problem is that WPF appearently clips the label to the edges of the grid cell before rotating the contents, so in my first attempt, the label was clipped at 27 units while it was horizontal, and then this less-that-a-third of the label was rotated to vertical position. I discovered that I could use Grid.ColumnSpan="4" to give the labels enough horizontal space to be drawn in full before rotating. That works only if three extra columns exist, and that holds true only for the first radio button. So I have to place all four of them in column 1 (spanning cols 1-4), and then translate them horizontally to appear visually over their intended columns.
This is ugly, messy, inflexible and most certainly not something I would like to maintain in the future, with columns added, widths/heights adjusted, labels changed...:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="120" />
<RowDefinition Height="27" />
<RowDefinition Height="27"/>
<RowDefinition Height="27"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="27"/>
<ColumnDefinition Width="27"/>
<ColumnDefinition Width="27"/>
<ColumnDefinition Width="27"/>
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="4" Content="Slett permanent" Height="120" Width="120" RenderTransformOrigin="0.5,0.5" VerticalAlignment="Center" >
<Label.RenderTransform>
<TransformGroup>
<RotateTransform Angle="270"/>
</TransformGroup>
</Label.RenderTransform>
</Label>
<Label Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="4" Content="Hopp over" Height="120" Width="120" RenderTransformOrigin="0.5,0.5" VerticalAlignment="Center" >
<Label.RenderTransform>
<TransformGroup>
<RotateTransform Angle="270"/>
<TranslateTransform X="27"/>
</TransformGroup>
</Label.RenderTransform>
</Label>
<Label Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="4" Content="Legg inn i SiKo" Height="120" Width="120" RenderTransformOrigin="0.5,0.5" VerticalAlignment="Center">
<Label.RenderTransform>
<TransformGroup>
<RotateTransform Angle="270"/>
<TranslateTransform X="54"/>
</TransformGroup>
</Label.RenderTransform>
</Label>
<Label Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="4" Content="Kopier til kildedisk" Height="120" Width="120" RenderTransformOrigin="0.5,0.5" VerticalAlignment="Center">
<Label.RenderTransform>
<TransformGroup>
<RotateTransform Angle="270"/>
<TranslateTransform X="81"/>
</TransformGroup>
</Label.RenderTransform>
</Label> Then follows code to fill the rows of the table below this top row.
There must be a simpler and better way to write a vertical (270 degrees rotated) text label over a column! But how?
(As you may see, I am certainly not a guru in XAML programming, so please be kiond to me )
|
|
|
|
|
There's few good reasons to use a Label over a TextBlock. You could try rotating a StackPanel with Labels.
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="120" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="1" RenderTransformOrigin="0.5,0.5">
<TextBlock.Inlines>
Slett permanent
<LineBreak />
Hopp over
<LineBreak />
Legg inn i SiKo
<LineBreak />
Kopier til kildedisk
</TextBlock.Inlines>
<TextBlock.RenderTransform>
<RotateTransform Angle="270" />
</TextBlock.RenderTransform>
</TextBlock>
</Grid>
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
|
Aaah - thanks a lot!
I hadn't leaned the difference between LayoutTransform and RenderTransform. Although LayoutTransform is mentioned in my XAML textbook, it isn't illustrated in an XAML example, so I hadn't grasped the difference between the two concepts.
LayoutTransfor gives me code that looks a lot more like I want it, a lot more direct and maintaninable.
(I still think XAML often requires an extreme amount of red tape to do fairly simple things. That is an inherent "quality" of XAML, not of transforms in particular, but it certainly is clearly illustrated in transforms!)
|
|
|
|
|
I have a behavior called SecurityBehavior that I'm using to control access to UI elements. I use it like this:
<TextBox Grid.Row="2"
Grid.Column="1"
Text="{Binding EmployeeName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Height="32"
Width="250"
local:SecurityBehavior.SecurityTags="can_add_employees|can_edit_employees"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Margin="5"/>
I set two tags that allows the field to be enabled if the user can Add or Edit the employee name.
Here's my Behavior class:
public static class SecurityBehavior
{
#region Security Tags
public static string GetSecurityTags(DependencyObject obj)
{
return (string)obj.GetValue(SecurityTagsProperty);
}
public static void SetSecurityTags(DependencyObject obj, string value)
{
obj.SetValue(SecurityTagsProperty, value);
}
public static readonly DependencyProperty SecurityTagsProperty =
DependencyProperty.RegisterAttached("SecurityTags",
typeof(string), typeof(SecurityBehavior),
new PropertyMetadata("", OnSecurityTagsChanged));
private static void OnSecurityTagsChanged(object sender, DependencyPropertyChangedEventArgs e)
{
FrameworkElement element = (FrameworkElement)sender;
bool canEnable = true;
var tags = e.NewValue.ToString().Split('|').ToList();
foreach (var tag in tags)
{
if (!string.IsNullOrEmpty(tag))
{
canEnable = canEnable & SecurityService.HasRights(tag);
}
}
element.IsEnabled = canEnable;
}
#endregion
}
Pretty straightforward. But now I ned one more thing. The UI's are always disabled until the "Edit" button on the toolbar is clicked. So, I added another DP like this:
<h1>region Allow Enable</h1>
public static bool GetAllowEnable(DependencyObject obj)
{
return (bool)obj.GetValue(AllowEnableProperty);
}
public static void SetAllowEnable(DependencyObject obj, bool value)
{
obj.SetValue(AllowEnableProperty, value);
}
public static readonly DependencyProperty AllowEnableProperty =
DependencyProperty.RegisterAttached("AllowEnable",
typeof(bool),
typeof(SecurityBehavior),
new PropertyMetadata(false, OnAllowEnableChanged));
private static void OnAllowEnableChanged(object sender, DependencyPropertyChangedEventArgs e)
{
FrameworkElement element = (FrameworkElement)sender;
}
<h1>endregion
and use it like this:
<TextBox Grid.Row="2"
Grid.Column="1"
Text="{Binding EmployeeName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Height="32"
Width="250"
local:SecurityBehavior.AllowEnable="{Binding AreFieldsEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
local:SecurityBehavior.SecurityTags="can_add_employees|can_edit_employees"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Margin="5"/>
The value of the VM's AreFieldsEnabled property is now passed to the DP AllowEnable. So far so good.
So I now tried to modify the OnSecurityTagsChanged method:
private static void OnSecurityTagsChanged(object sender, DependencyPropertyChangedEventArgs e)
{
FrameworkElement element = (FrameworkElement)sender;
var allowEnable = AllowEnable;
bool canEnable = true;
var tags = e.NewValue.ToString().Split('|').ToList();
foreach (var tag in tags)
{
if (!string.IsNullOrEmpty(tag))
{
canEnable = canEnable & SecurityService.HasRights(tag);
}
}
element.IsEnabled = canEnable;
}
I get a compilation error on the line with the commnent. How do I read the value of the other DP??
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
It's an attached property, so you need to either call the attached property accessor, or call GetValue and pass in the dependency property.
Try something like this:
public static class SecurityBehavior
{
private static readonly char[] TagSeparators = { '|' };
public static readonly DependencyProperty SecurityTagsProperty =
DependencyProperty.RegisterAttached("SecurityTags",
typeof(string), typeof(SecurityBehavior),
new PropertyMetadata("", OnSecurityChanged));
public static string GetSecurityTags(DependencyObject obj)
{
return (string)obj.GetValue(SecurityTagsProperty);
}
public static void SetSecurityTags(DependencyObject obj, string value)
{
obj.SetValue(SecurityTagsProperty, value);
}
public static readonly DependencyProperty AllowEnableProperty =
DependencyProperty.RegisterAttached("AllowEnable",
typeof(bool),
typeof(SecurityBehavior),
new PropertyMetadata(false, OnSecurityChanged));
public static bool GetAllowEnable(DependencyObject obj)
{
return (bool)obj.GetValue(AllowEnableProperty);
}
public static void SetAllowEnable(DependencyObject obj, bool value)
{
obj.SetValue(AllowEnableProperty, value);
}
private static void OnSecurityChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
bool canEnable = GetAllowEnable(sender);
if (canEnable)
{
string[] tags = GetSecurityTags(sender).Split(TagSeparators, StringSplitOptions.RemoveEmptyEntries);
foreach (string tag in tags)
{
canEnable &= SecurityService.HasRights(tag);
}
}
var element = (UIElement)sender;
element.IsEnabled = canEnable;
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Ok, so I implemented your changes and the GetAllowEnable(sender) gets called fine. However, overall things still don't work right. Let me explain...
This is all in a small WPF test app. On the window I have a TextBox, and a ToggleButton called Enabled. When the Toggle is clicked, I set a property in the code behind called AreFieldsEnabled to True. This property is bound on the TextBox to the SecurityBehavior's AllowEnable DP:
<TextBox Grid.Row="2"
Grid.Column="1"
Text="{Binding EmployeeName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Height="32"
Width="250"
local:SecurityBehavior.AllowEnable="{Binding AreFieldsEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
local:SecurityBehavior.SecurityTags="can_add_employees|can_edit_employees"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Margin="5"/>
The problem is that the SecurityTags DP gets called first, which calls GetAllowEnable, which return False by default because AllowEnable hasn't yet been set to True (using the ToggleButton). Later, when I toggle the button and set AreFieldsEnabled to True, the SecurityTags property is never called again, so nothing is enabled. Here's all the code:
Behavior
public static class SecurityBehavior
{
private static readonly char[] TagSeparators = { '|' };
#region Allow Enable
public static readonly DependencyProperty AllowEnableProperty =
DependencyProperty.RegisterAttached("AllowEnable",
typeof(bool),
typeof(SecurityBehavior),
new PropertyMetadata(false, OnAllowEnableChanged));
public static bool GetAllowEnable(DependencyObject obj)
{
return (bool)obj.GetValue(AllowEnableProperty);
}
public static void SetAllowEnable(DependencyObject obj, bool value)
{
obj.SetValue(AllowEnableProperty, value);
}
private static void OnAllowEnableChanged(object sender, DependencyPropertyChangedEventArgs e)
{
FrameworkElement element = (FrameworkElement)sender;
}
#endregion
#region Security Tags
public static readonly DependencyProperty SecurityTagsProperty =
DependencyProperty.RegisterAttached("SecurityTags",
typeof(string), typeof(SecurityBehavior),
new PropertyMetadata("", OnSecurityChanged));
public static string GetSecurityTags(DependencyObject obj)
{
return (string)obj.GetValue(SecurityTagsProperty);
}
public static void SetSecurityTags(DependencyObject obj, string value)
{
obj.SetValue(SecurityTagsProperty, value);
}
private static void OnSecurityChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
bool canEnable = GetAllowEnable(sender);
if (canEnable)
{
string[] tags = GetSecurityTags(sender).Split(TagSeparators, StringSplitOptions.RemoveEmptyEntries);
foreach (string tag in tags)
{
canEnable &= SecurityService.HasRights(tag);
}
}
var element = (UIElement)sender;
element.IsEnabled = canEnable;
}
#endregion
}
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
If you look at my code again, both DPs call the same "property changed" method. Your AllowEnable property is calling an almost empty method instead.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Yup, I'm an idiot.
Thanks!
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Hi, I have a need to link two xaml windows due to a constraint on xml processing. Instead of sending one xml request, I have to send two.
I have some some research, and there is not a whole lot on doing this. I found an article that discussed:
How can i combine multiple XAML files using C# in WPF? - Stack Overflow[^]
Can anyone steer me in the right direction? I just want to run one xaml window then the next.
I put them into my project and nothing happened. I did not receive an error, but nothing happened.
|
|
|
|
|