|
I am guessing that everything is done on the main thread so the UI thread locks until the method is completed and the last colour change is effected.
Unless you do the export on a separate thread you are not going to see the initial colour change. putting in a delay does not help, move the export to a BGW thread.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
i actually tried that initially. by setting the color from another Thread and the Export is obviously in another thread. but still the issue remains , let me keep trying something will post the feedback if i get to the solution.
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vimalsoft.com
vuyiswa[at]vimalsoft.com
|
|
|
|
|
No no no, you set the colour BEFORE you launch the BGW that exports the excel, in the BGW compleate method you set the colour the second time.
This allows the UI to refresh while the BGW is working.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
You are 100% Right, i was missing Something. its now working like charm.
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vimalsoft.com
vuyiswa[at]vimalsoft.com
|
|
|
|
|
- How do you unit test a piece of UI becoming visible/invisible? The bound bool may be correct, but the converter could fail.
- How do you unit test data validations?
If it's not broken, fix it until it is
|
|
|
|
|
Kevin Marois wrote: How do you unit test a piece of UI becoming visible/invisible? The bound bool may be correct, but the converter could fail. If you're that worried about the converter, you would write a UI automation test. However, a better bet would be to write a unit test for your converter to ensure it responds to changes (this is assuming you aren't using the standard visibility converter for some reason - but why would that one fail).
Kevin Marois wrote: How do you unit test data validations? Again, you test the underlying logic. If you are worried about UI behaviour, write UI automation tests.
This space for rent
|
|
|
|
|
Thanks.
I'm trying to write units tests to test acceptance criteria, and some of states "When this is true then this UI part should visible".
So it's not really about the converter as much as it is aligning tests with acceptance with the idea being that after any form of refactoring, the UI part is still respecting the condition.
If it's not broken, fix it until it is
|
|
|
|
|
In which case, a Coded Unit Test[^] is probably going to be your best bet.
This space for rent
|
|
|
|
|
Pete O'Hanlon wrote: (this is assuming you aren't using the standard visibility converter Where be this standard converter!
I have a bunch of converters that I call standard I did not know there are built in converters!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
System.Windows.BooleanToVisibilityConverter. There are other converters that do things for you behind the scenes such as this[^] puppy.
This space for rent
|
|
|
|
|
Thank you, that gets rid of a folder of converters I have been using for ages. CP continues to be of value.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
You're welcome. I have to admit that I'm not the biggest fan of converters - they do tend to be misused a lot to by people trying to shoehorn functionality in that either belongs in a VM, or which can readily be done with triggers.
This space for rent
|
|
|
|
|
hi i am using wpf vs.net 2012 to do a simple optimization program for myself.
my goal is to load from a png file and be able to print the file to a a4 size paper after editing it a little(like adding my name).
at the moment i am using canvas control hold and print the image from.
i notice that this does not seems to be the best option. is there a more efficient way then using canvas?
|
|
|
|
|
Hello,
I'm looking for a simple XAML + C# code the does the following:
Upon application launch, loading 3 icons from png files into an image list.
On runtime (e.g every 1 sec) a new line is added to a ListView. Each row contains an icon + label.
The icon can be one out of the 3 previously loaded icons.
The XAML I currently have is (not sure it's OK):
<Window.Resources>
<sys:String x:Key="icon1">icon1.png</sys:String>
<sys:String x:Key="icon2">icon2.png</sys:String>
<sys:String x:Key="icon3">icon3.png</sys:String>
</Window.Resources>
...
<ListView x:Name="listView1" >
<ListView.ItemTemplate>
<DataTemplate>
<Image Source="{Binding}" Stretch="None" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Can you please send a C# code ?
Best regards,
Z.V
|
|
|
|
|
Sorry, but we don't write your code for you.
Why don't you try it yourself first, and then if you have a specific question, come back to ask it. If you do that, people will gladly help you.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
|
Hello,
I used the following XAML code:
<StackPanel x:Name="grd">
<ListView x:Name="listView">
<ListView.View>
<GridView>
<GridViewColumn Header="Severity" DisplayMemberBinding="{Binding Icon}"/>
<GridViewColumn Header="Id" DisplayMemberBinding="{Binding Id}"/>
<GridViewColumn Header="Name" DisplayMemberBinding="{Binding Name}"/>
<GridViewColumn Header="Immagine" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<Image Source="{Binding ImagePath}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</StackPanel>
</Window>
And the following C# code:
public partial class MainWindow : Window
{
public class MyItem
{
public string Icon { get; set; }
public int Id { get; set; }
public string Name { get; set; }
public string ImagePath { get; set; }
}
public MainWindow()
{
InitializeComponent();
MyItem Item = new MyItem();
Item.Icon = "1";
Item.Id = 0;
Item.Name = "Zvika";
Item.ImagePath = "icon1.png";
this.listView.Items.Add(Item);
}
}
I also added the file icon.png to the project.
Now it works.
Regards,
Z.V
modified 30-Dec-15 21:44pm.
|
|
|
|
|
I know that is an aberration but I am building a TreeListView where the Tree Column [0] is fixed and the following columns are dynamically created as a collection of columns in the viewmodel. The code behind then adds the columns to the TreeListView when they are built.
The creation of the columns is done on a BGW and a message is generated for the code behind to consume in the BGW complete method.
However the Message is complaining that it is on the wrong thread.
VM BGW Complete Method
private void NavComplete(object sender, RunWorkerCompletedEventArgs e)
{
worker.DoWork -= LoadTreeStuff; ;
worker.RunWorkerCompleted -= NavComplete; ;
if (e.Result != null)
{
MessageBox.Show(e.Result.ToString());
}
BusyIndicator = false;
AppMessages.MessageObject.Send("ColumnsReady");
}
I would have thought the AppMessage.MessageObject.Send would be on the main application thread.
public static class MessageObject
{
public static void Send(object oPayload)
{
Messenger.Default.Send<object>(oPayload);<-------Errors
}
<pre>
public static void Register(object recipient, Action<object> action)
{
Messenger.Default.Register<object>(recipient, action);
}
public static void UnRegister(object recipient)
{
Messenger.Default.Unregister<object>(recipient);
}
}</pre>
with the following error
Quote: The calling thread cannot access this object because a different thread owns it.
Any suggestions other than getting rid of the BGW (works perfection when it is removed)
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Wrap the code that's failing in a Dispatcher.Invoke (or Dispatcher.BeginInvoke) to marshall the code back to the correct thread.
This space for rent
|
|
|
|
|
I'm learning WPF. Over the past couple of days, I've worked my way through one-way binding, two-way binding, and list binding. For each of these, I created my own model classes to hold the data displayed on the window.
Now I'm tackling Entity Framework. Instead of using my own model classes, I want to use a data model created by the Entity Framework designer. I just tried it and it works beautifully. Even though it works, however, there is one thing I don't understand: Why does Visual Studio think I need a database?
For my simple test project, I'm not using any persistent data, and therefore I don't need a database. In my code, I create a Data Model Container and interact only with the in-memory version of the data (which I believe is done by specifying "Local" whenever referring to a table). Even though I don't need a database, Visual Studio kept giving me warnings related to the "Table Mapping" until I created one. After I created a database and connection string, everything worked properly with no errors or warnings.
As a test, I then deleted the database and changed the connection string in App.config to something bogus. Everything continued to work properly, indicating that the database and connection string are unused. It is only when I delete the connection string completely that I get errors again.
So my question is this: Why is Visual Studio insisting that I have a connection string which it obviously isn't using?
-TC
PS: I suppose this question is about Entity Framework more than WPF, but I came to the question through my research on WPF, so I hope it is appropriate for this forum. If not, let me know and I'll gladly repost elsewhere.
|
|
|
|
|
Caveat - I am extremely prejudiced...
Entityframework is the work of satan, it wraps up your data management and ORM into a black box and then feeds you the nice, sanitised data titbits. It also tries to do everything for everyone and is therefore a monster.
You end up with a programmer who knows how to use EF but does not understand the underlying data management or how the ORM works and how he got his sanitised object. When it does go wrong they will try and work around it withing the EF structure, not understanding the fundamental problem that caused the error!
If you do not need a database (you will for your production system) are yo even contemplating including EF in you project.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote: Entityframework is the work of satan, it wraps up your data management and ORM into a black box and then feeds you the nice, sanitised data titbits. It also tries to do everything for everyone and is therefore a monster.
You end up with a programmer who knows how to use EF but does not understand the underlying data management or how the ORM works and how he got his sanitised object. When it does go wrong they will try and work around it withing the EF structure, not understanding the fundamental problem that caused the error!
Thank you for that advice. I am wary of technologies that obscure, rather than clarify, what is going on behind the scenes. From your comments, it sounds like Entity Framework is one such technology, so I'll be careful.
Mycroft Holmes wrote: If you do not need a database (you will for your production system) are yo even contemplating including EF in you project.
I'm not sure I understand the question. Are you implying that Entity Framework only merits contemplation when a database is required?
-TC
|
|
|
|
|
_T_C_ wrote: Are you implying that Entity Framework only merits contemplation when a database is required? AFAIK that is EFs primary functionality, model and manage the movement of data from the store to the business layer. Remembering that my knowledge of EF is pretty shallow
Most of us will have built our own ORM and data access layer, some predating EF by some years, mine started out in the mid 90s!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
The connection string does more than specify a database: it identifies an EF compatible data provider (which could be based on Excel for that matter).
I suspect that if you tried to "save" your entities, you would get an error if the connection string is invalid and / or the database is missing; EF is not using the connection (string) until it needs it.
There is more than one way to supply a connection (string) to a dbContext; the app.config file is the default. If you created the dbContext with an invalid string in the constructor, that would probably work too for the time being.
(All just speculation since I tend to use the "typical" case).
|
|
|
|
|
Mr. Holmes and Mr. Schmitz,
Thank you for the replies. I appreciate the information you've provided, but I must be failing to grasp some key concept because Entity Framework's behavior in this respect still seems like a mystery to me. In an attempt to get at the answer from a different direction, let me turn the question around and ask it this way: If you had to code an application which generates a few megabytes of relational data, with no requirement to save those data, what technology would you use?
I would expect that to be a common scenario. A lot of extract/transform/load applications would probably fit that description. Let me offer a specific example: I need to read lab data from a few data sources, then filter, transform, and analyze the data, then offer a few charts & reports and the ability to export the results in various formats. What technologies would be useful for such a project?
To my uninformed eye, Entity Framework seems a likely candidate. With Entity Framework, I can define the data model for my generated data using an intuitive GUI, and Entity Designer will write code to implement all the entities, relationships, and constraints for me. That will save me some time and enforce some consistency. Better yet, my data model will be self-documented in a relationship diagram, right there in the Visual Studio project, which is far better than any alternative I can think of. Why wouldn't I use Entity Framework for that reason alone? Even though I'm not using Entity Framework's ORM capabilities, those are a bonus too, because I have an easy migration path if the project ever evolves into something that requires persistent data. Furthermore, it means the data modeling syntax for this project will be the same as the data modeling syntax for other projects which require Entity Framework's ORM capabilities, lessening the overall learning curve for my team.
But if Entity Framework is really appropriate for this scenario, then why is it demanding a connection string? That one detail has made me suspicious that I am missing something which makes Entity framework wholly inappropriate here. I feel that I need to keep digging until I figure it out.
Please let me know if you have any further insight. In any case, I thank you for the advice you've provided thus far.
-TC
|
|
|
|