|
And that's the problem! If you block the UI thread, then the UI won't update.
Move the blocking code to a background thread. The simplest way to do that is using a BackgroundWorker [^].
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
How to Generate the SSRS report in WPF and explain through the code
|
|
|
|
|
|
How to Delete the multiple records in wpf datagrid using threetier architecture
|
|
|
|
|
Requires multi-select enabled in the data grid and one delete command per selected record.
The Master said, 'Am I indeed possessed of knowledge? I am not knowing. But if a mean person, who appears quite empty-like, ask anything of me, I set it forth from one end to the other, and exhaust it.'
― Confucian Analects
|
|
|
|
|
Hi
I have a WPF project working fine in Windows 7, but which has a completely changed layout, when the same project is executed under Windows 10.
Do any of you have experiences with this issue?
I have found out that WPF loads the current theme/skin from the OS, and that this may be the cause of the skewed layout, but I haven't been able to find any whitepapers or guides with information on how to work around this problem.
It is a basic Grid with Stack Panels and Labels in it, if that helps.
Any help/ideas/links would be much appreciated
Kind regards - Jakob
|
|
|
|
|
Hi Jakob,
I had experience with this in the past, but visual changes between two OS versions were usually minor. What do you mean by "completely changed layout"? Can you please elaborate?
As you pointed out, issue is (probably) about the styles and templates. By manually setting the whole style (with template etc.), you should be able to ensure same visual appearance on any (compatible) OS.
|
|
|
|
|
Hi Jimmson
Thank you for replying.
I have been isolating diffent parts of our code, to find the culprit.
We are basically building a custom WPF control runtime, to use it for printing, but since it is never shown on the UI, but sent off to the printer, the WPF framework doesn't perform lay-out on the control.
I understand, that these lines in the code I am trying to get to work on WIN10, are responsible for enforcing the layout functionality in a non-visible control:
fixedPage.Measure(sizeOfCustomControlToPrint);
fixedPage.Arrange(new Rect(new Point(), sizeOfCustomControlToPrint));
fixedPage.UpdateLayout();
if I comment these out in WIN10, it seems to be working, but I would really like to understand why.
Maybe there is a bug in the WIN10 implementation...?
|
|
|
|
|
Have you tried to display this FixedPage in UI to see whether the problem actually is in the FixedPage, or in your custom WPF control runtime?
|
|
|
|
|
Great idea...
It's off to the code-cave!
|
|
|
|
|
You're doing "measures" and "arranges" based on a control whose dimensions you have not ascertained.
What was a number in Win 7 could now be a NAN in Win 10, or vise-versa.
You use the debugger, "Live Visual Tree" and "Live property view" to confirm the heights and width are inherited / accessed as expected.
The Master said, 'Am I indeed possessed of knowledge? I am not knowing. But if a mean person, who appears quite empty-like, ask anything of me, I set it forth from one end to the other, and exhaust it.'
― Confucian Analects
|
|
|
|
|
Good points. Thanks, Gerry
|
|
|
|
|
I have a 50,000 line Windows done by someone else that I need to migrated to a WPF. It has 35 forms. I need to do it gradually. I have found article to use both kinds of forms in the same project.
How well does it work? I know it will be clunky for awhile.
So many years of programming I have forgotten more languages than I know.
|
|
|
|
|
It depends on how independent the forms are. If they don't have lots of dependencies on each other, the experience of hosting them is fairly seamless. The styling, on the other hand....
|
|
|
|
|
I never thought about the styling. Thanks for the reminder.
There is one main form with a large panel in the middle and navigation buttons and status summaries around it. There are 3 panel forms and 2 tab containers. Each tab contains a separate form. They are all loaded and running all the time. Only one shows at a time. There are also a bunch of popups.
So many years of programming I have forgotten more languages than I know.
|
|
|
|
|
bonjour,
J'ai un RichTextBox dans le quel il y a un FlowDocument
je crée un tableau par code
le tableau s'affiche correctement
je le sauvegarde en RTF .
je perds les mises en forme
seul le Background est bon
Merci de votre réponse
un bout du code
Google Translate: Hello,
I have a RichTextBox in which there is a FlowDocument
I create a table by code
the table is displayed correctly
I save it in RTF.
I lose the formatting
only the Background is good
Thank you for your reply
a piece of code
private void button2_Click_1(object sender, RoutedEventArgs e)
{
Table T = new Table();
myFlowDoc.Blocks.Add(T);
T.CellSpacing = 1;
for (int x = 0;x<5;x++) { T.Columns.Add(new TableColumn()); }
T.Columns[0].Background = Brushes.Beige;
T.Columns[0].Width = new GridLength(200);
T.Columns[1].Width = new GridLength(150);
T.Columns[2].Width = new GridLength(60);
T.Columns[3].Width = new GridLength(100);
T.Columns[4].Width = new GridLength(100);
T.BorderThickness = new Thickness(1);
T.BorderBrush = Brushes.Red;
T.RowGroups.Add(new TableRowGroup());
T.RowGroups[0].Rows.Add(new TableRow());
TableRow currentRow = T.RowGroups[0].Rows[0];
currentRow.FontWeight = FontWeights.Bold;
currentRow.Background = Brushes.Silver;
currentRow.FontSize = 20;
TableCell TC = new TableCell();
currentRow.Cells.Add(TC);
TC.TextAlignment = TextAlignment.Center;
myParagraph = new Paragraph(new Run("Résultat des mesures "));
TC.Blocks.Add(myParagraph);
|
|
|
|
|
This is an English language site, and we can only respond to questions in that language. I have used Google Translate to modify your question, but you should check that the English meaning is unchanged from your original.
In future, please use Google or Bing to translate your French to English.
And please, use the "code" widget (or select "Code Block" when you paste code samples to ensure that the formatting is preserved.
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
There is no direct way to get "rtf" from a RichTextBox.
In terms of "saving and restoring", do the following:
How to: Save, Load, and Print RichTextBox Content | Microsoft Docs
The Master said, 'Am I indeed possessed of knowledge? I am not knowing. But if a mean person, who appears quite empty-like, ask anything of me, I set it forth from one end to the other, and exhaust it.'
― Confucian Analects
|
|
|
|
|
Hello
Thank you for your reply
Difficult for me, I do not speak English
My problem: I create a table by code. It is displayed well.
I record it in RTF. I lose the formatting. Size Bold ...
but the Background is good (currentRow.Background = Brushes.Silver;)
If I change with a button
example: Command = "ToggleBold"
the formatting is preserved
Very weird
THANK YOU :
the grandpa who went to computer without speaking a word of English
|
|
|
|
|
A WPF RichTextBox uses XAML internally; not RTF.
They should have called it XamlBox, I guess.
The Master said, 'Am I indeed possessed of knowledge? I am not knowing. But if a mean person, who appears quite empty-like, ask anything of me, I set it forth from one end to the other, and exhaust it.'
― Confucian Analects
|
|
|
|
|
I have this WPF ListBox:
<pre><ListBox Grid.Row="4"
Grid.Column="1"
ItemsSource="{Binding RuleActionsList}"
SelectionMode="Multiple"
Margin="5"
Style="{StaticResource ListBoxStyle}">
<pre>
<i:Interaction.Behaviors>
<cls:MultiSelectionBehavior SelectedItems="{Binding SelectedRuleActions}" />
</i:Interaction.Behaviors>
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Converter={StaticResource enumDescConv}}"
Margin="2"/>
</DataTemplate>
</ListBox.ItemTemplate>
The SelectedItems is bound to a behavior that update the ListBox's SelectedItems list. This part works fine.
The question is, how do I validate that there is at least one list item selected? Where do you set ValidatesOnNotifyDataErrors?
For other properties on the model, Iset ValidatesOnNotifyDataErrors=True and then do:
private void ValidateProperty(string propertyName)
{
if (RuleGroup.Errors.TryGetValue(propertyName, out List<string> errors))
{
errors.Clear();
}
else
{
errors = new List<string>();
}
switch (propertyName)
{
case "GroupName":
if (RuleGroup.GroupName == null)
{
errors.Add("The Group Name cannot be empty");
}
break;
}
RuleGroup.Errors[propertyName] = errors;
if (errors.Count > 0)
{
RuleGroup.RaiseErrorsChanged(propertyName);
}
}
and then
private void RuleGroup_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
ValidateAll();
}
The property chaneg calls the validate, and for any property that is invalid I see the red box around the field in the ui.
But how do I do the same for the SelectedItems property?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
modified 22-Jul-19 15:45pm.
|
|
|
|
|
I have a Contacts control. On the left side is the list of contacts. I created two DataTempates for the list items in the Control's resources.
Above the list are two buttons, List View and Card View. When they are selected, I want to change the data template of the list items accordingly.
Here's a picture of Outlook Contacts showing the People button selected above the list. When one of the Current View buttons is selected, the list box items look different. This is what I'm looking for:
https://www.brycematheson.io/wp-content/uploads/2018/04/Image1_Blurred-1024x713.jpg
I have a DataTemplateSelector, but when it' called the container property is the ListItem. How do I know in the DataTemplateSelector what view mode was selected in the ViewModel?
By DataTemplateSelector
public class ContactViewDataTemplateSelector : DataTemplateSelector
{
public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
FrameworkElement element = container as FrameworkElement;
ContactsView view = container as ContactsView;
switch (view.ViewMode)
{
case ContactsView.ViewModes.Card:
return element.FindResource("cardViewTemplate") as DataTemplate;
break;
case ContactsView.ViewModes.List:
return element.FindResource("listViewTemplate") as DataTemplate;
break;
}
return null;
}
}
DataTemplates
<cls:ContactViewDataTemplateSelector x:Key="contactViewDataTemplateSelector" />
<DataTemplate x:Key="listViewTemplate">
<TextBlock Text="{Binding DisplayName}"
FontSize="18"/>
</DataTemplate>
<DataTemplate x:Key="cardViewTemplate">
<pre>
<Border Padding="2"
Margin="2"
BorderBrush="SteelBlue"
BorderThickness="1"
CornerRadius="5">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Text="{Binding FullName}"
FontWeight="Bold"
Foreground="Black"
FontSize="18"/>
<TextBlock Text="{Binding Title}"
Foreground="Black"
FontSize="18"/>
<TextBlock Text="{Binding Company}"
Foreground="Black"
FontSize="18"/>
</Grid>
</Border>
ListBox
<ListBox Grid.Row="0"
Grid.Column="0"
ItemsSource="{Binding Contacts, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
SelectedItem="{Binding SelectedContact, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
ItemTemplateSelector="{StaticResource contactViewDataTemplateSelector}"
MinWidth="175"
Margin="2"/>
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
You've got the ListItem ; you just need to use something like this function[^] to walk up the tree to find the control, and grab its DataContext property, which should be your ContactsView .
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
The problem is that the DataTemplateSelector gives me the ContactEntity, not the ListItem
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
That did it. Here's what I came up with:
<pre>public static class VisualTreeExtensions
{
public static T FindParentOfType<T>(this DependencyObject child) where T : DependencyObject
{
DependencyObject parentDepObj = child;
do
{
parentDepObj = VisualTreeHelper.GetParent(parentDepObj);
T parent = parentDepObj as T;
if (parent != null) return parent;
}
while (parentDepObj != null);
return null;
}
}
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|