|
|
|
Hi,
I have a wpf application and for DispatcherUnhandledException exception, I want to write an entry in system log.
if (!EventLog.SourceExists("ApplicationName"))
EventLog.CreateEventSource("ApplicationName", "Error Log");
EventLog.WriteEntry("ApplicationName", e.Exception.Message + "\n" + "Stack Trace:" + "\n" + e.Exception.StackTrace,EventLogEntryType.Error);
Above code is working fine on development machine on deployment, since I have administrative rights.
But on the client machine, user not having administrative rights can not run application on clickOnce deployment.
This is because EventLog.CreateEventSource method requires administrative rights.
ClickOnce deployment is per user deployment and very handy.
So, I was wondering if there is any technique to write event logs.
I am writing errorlog to a text file for now.
Thanks,
Vsaratkar
|
|
|
|
|
Can anybody point me in the right direction how to do this please.
I have found a few samples showing how to do it in WinForms but they all say it doesn't work in WPF.
The files I will be dragging into the WPF app will all be text files so it doesn't need anything fancy.
|
|
|
|
|
The functionality in this[^] article works in WPF."WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Thanks, that works. I had seen it during an earlier search but it only does single files - but its better than no files so it will do for now
|
|
|
|
|
Hello,
Someone in Silverlight posted[^] that MVVM currently lacks standardization so that everyone has own favor..
That's why Me and a few guys from WPF Disciples are actively discussing about MVVM that everyone agreed. I totally understand that we have implemented the pattern in different ways and we mixed the several patterns or create our own pattern based on our project's need or to make the developers' life easier.. But forget about those difficulties or the special need of your project. Let's discuss about the standard rules of MVVM pattern that everyone agreed. I posted some of my thoughts here[^] as well.
Why MVVM?
- Testabiltiy ( ViewModel is easier to unit test than code-behind or event driven code)
- Clear seperation between UX designer and developer
- Increases the “Blendability” of your view
- Model never needs to be changed to support changes to the view
- ViewModel rarely needs to be changed to support changes to the view
- No duplicated code to update views
Do and Don’t in View
- shouldn’t contain any logic that you want to test : As Glenn said that MVVM is not code counting exercise, we can write code in code-behind. But you should never write any logic that you want to test. For example: If user select a country then you want to display the list of states or city in your view. This is the business requirement so you should have unit test to test this logic. So, you shouldn’t write it in code-behind.
- can be a control or Data Template
- Keep the view as simple as possible. : We can still use Data Trigger or Value Converter or Visual State or Blend Behivor in XAML with care.
- use attached property if something is not bindable :
Do and Don’t in ViewModel
- Connector between View and Model
- Keep View State, Value Conversion (You can create the data structure that you want to display in ViewModel instead of using ValueConverter. For example: You need to show the Name instead of First Name and Last name. Your Model can have First Name and Last Name but You can create Name property in ViewModel. )
- No strong or weak (via Interface) reference of View
- Make VM as testable as possible (e.g. no call to Singleton class)
- No Control related Stuff in VM ( Because if you are changing the view then you will have to change VM as well. )
Model
- can be Data Model, DTO, POCO, auto-generated proxy of domain class and UI Model based on how you want to have the separation between Domain Service and Presentation Layer
- No reference to ViewModel
Do you have any suggestion or comment for that?
We have one disagreement in our group. Some said that it's okay to have the interface of View in ViewModel. But some said that if View Model has the interface of View then it will be MVP pattern.
One of our MVVM experts say about MVVM Vs MVP
**View => ViewModel**
- MVVM the view is directly bound to the ViewModel and talks to the VM through databinding
- In MVP, the view is bound to a model hanging off the SupervisingController or not bound at all (passive view).
**ViewModel => View**
MVVM
1. INPC / Property binding
2. Events
3. Messages (Event Aggregator/Messenger/RX framework)
4. Through an intermediary such as a service
5. Through an interface
6. Through delegates (View passes delegates to the VM which it can use to call it back. For example VM might expose a SetActions method which the View calls passing it delegates.
MVP
1. With Passive View the properties are not using databinding, instead the view property getters and setters are used to directly set the control value.
2. Events
3. Messages (Event Aggregator/Messenger/RX framework)
4. Through an intermediary such as a service
5. Through an interface
6. Through delegates (View passes delegates to the VM which it can use to call it back. For example VM might expose a SetActions method which the View calls passing it delegates.
MVP Vs MVVM
All are the same except the following.
1. View talks to ViewModel via binding. In MVP, View directly calls the Presenter.
2. ViewModel has INPC / Property binding while Presenter doesn't have. Presenter set the value to the property of control directly.
The rest are the same.
What do you think about that idea?
Do you think that it's okay for ViewModel have the interface of View?
If you like to add more then you are welcome to add...
The whole idea about this post is to get the same understanding of MVVM pattern in Community. Feel free to let me know if you have any comment or doubt. Thanks.modified on Sunday, February 7, 2010 10:10 PM
|
|
|
|
|
Michael Sync wrote: Do you think that it's okay for ViewModel have the interface of View
There is one simple reason why I think that it's okay for the VM to have a reference to the interface for the view.... I do not know of any reason why it is forbidden.... it's not like you are directly referencing a View.... it's an interface that the view happens to implement. Many views can implement the same interface so you are not tying the VM to a particular view.Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
Help humanity, join the CodeProject grid computing team here
|
|
|
|
|
Hi, I managed to bring to work simple data template in a ListView control:
<DataTemplate>
<TextBox Text="{Binding Path=boo}" />
</DataTemplate>
Class of the items added to the ListView contains property 'boo' of type string.
But how to do similar binding for a custom complex type. Let's say instead of string boo,
I have List<int> integers; . What I'm trying to achieve is to make the textbox display
the numbers in the list separated with commas (e.g. 3,5,15,2).
In other words, is it possible to do something like
<TextBox Text="{Binding Path=integers}" /> by providing how the target should be formatted?
The main issue is that it should be a two-way binding (with ability to convert "1,5,4" back to List<int>).
What direction to go? I assume I could implement a string property, i.e. 'NumbersString' returning
joined contents of the list in form of a single string. Or maybe it has something to do with converters?
I only hope my explanation is clear enough.
Thanks in advance,
Paul
|
|
|
|
|
One way to do this would be to use a ViewModel approach, and bind to a string property that aggregates this data. Consider the following sample:
public class MyClass
{
private List<int> _myList = new List<int>();
public string AggregateList
{
get
{
if (_myList != null && _myList.Count > 0)
{
StringBuilder myString = new StringBuilder();
foreach (int value in _myList)
{
sb.AppendFormat("{0},", value);
}
return sb.ToString().Substring(0, sb.ToString().Length - 2);
}
return string.Empty;
}
set
{
string[] values = value.Split(",");
_myList.Clear();
foreach (string item in values)
{
int output;
if (int.TryParse(item, out output))
{
_myList.Add(output);
}
}
}
}
} You could do something like this using converters, but this is a simple method - and you just need to bind to this property. I've just knocked this up in the HTML editor here, so there may be a mistake or two, so I apologise in advance for them."WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Thank you for your time!
This should be enough in some cases, including my current issue, but it seems somewhat less flexible.
Let me be a bit curious, so what if an user wants to write his own style(?) and have the data separated
with semicolons, not commas?
May seem overcomplicated, but I'm asking, because it may happen that the end-user will be unable to
change the data input. So the List<int> will be always a List<int> without a chance to wrap it as above.
Thanks once again! Anyway I've just found a site about converter binding in xaml and I think it can be
highly educational.
|
|
|
|
|
You could use a converter if you wanted - if the user wants to write his own style though, you are faced with having to change the code anyway. The sample I posted was aimed at satisfying your problem - it's designed around POCO (Plain Old CLR Objects) which means that it's easy to test."WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
You could put the textbox in a stackpanel and then set the stackpanel's orientation to horizontal.Me, I'm dishonest. And a dishonest man you can always trust to be dishonest. Honestly. It's the honest ones you want to watch out for...
|
|
|
|
|
|
I don't get the point. Did you mean adding multiple textboxes to that StackPanel?
|
|
|
|
|
<ListBox x:Name="DemoList"> <br />
<ListBox.ItemsPanel> <br />
<ItemsPanelTemplate> <br />
<StackPanel Orientation="Horizontal" /> <br />
</ItemsPanelTemplate> <br />
</ListBox.ItemsPanel> <br />
<DataTemplate> <br />
<Grid><br />
<Grid.ColumnDefinitions><br />
<ColumnDefinition><br />
<ColumnDefinition><br />
</Grid.ColumnDefinitions><br />
</Grid><br />
<TextBox grid.column=0 Text1="{Binding integers}"/><br />
<TextBox grid.column=1 Text1=";"/><br />
</DataTemplate><br />
</ListBox>
You might also want to take a look here[^].
|
|
|
|
|
The original question was how could you wrap the list into one textbox, not how to display the list horizontally."WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Good people,
I built an application in WPF. It uses a splash screen.
Sometimes when I (and presumably other people) am starting an application, I click on it and switch to another app that I am working on. However, it seems that the app I built will only load properly if I don't click on anything and let it fully load before switching to another application or otherwise clicking anywhere on the screen. If, at any time between the splash screen and the main window loading I click on another application or send open something else, the computer says that my app has an error and it has to shut down.
Do you have any thoughts about how to make it more robust so that it can load without being so vulnerable to other clicks?
Thanks in advance for any help you can provide.
|
|
|
|
|
Dear friends ... i am new to WPF
i have a rounded shape like these
<Window x:Class="ProtonUI.Logon"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Logon" Height="381" Width="500">
<Grid>
<Path Name="xyz" Data="F1M85.679,25.511C85.679,39.6 74.257,51.024 60.167,51.024 46.077,51.024 34.655,39.6 34.655,25.511 34.655,11.422 46.077,0 60.167,0 74.257,0 85.679,11.422 85.679,25.511z" Margin="149,0,230,63" Name="path1" Height="74.976" VerticalAlignment="Bottom" Grid.ColumnSpan="2">
<Path.Fill>
<LinearGradientBrush EndPoint="141.363,252.324" MappingMode="Absolute" StartPoint="141.363,201.3" Transform="1,0,0,-1,-81.196,252.324">
<GradientStop Color="White" Offset="0" />
<GradientStop Color="#FF020202" Offset="1" />
</LinearGradientBrush>
</Path.Fill>
</Path>
</Grid>
</Window>
now i want mouseover event for this shape ? how to create?
when i see property window for this shape there are lot of events , but when i double click on the event ... i get an message ...
like these...
"To generate an event handler the class 'logon',specified by the x:Class or x:Subclass attribute,must be the first class in the file. move the class code so the it is the first class in the file and try again"
sorry i could not understand what the message says ...
can some one correct me ....
by
joe
|
|
|
|
|
Hi,
Does anyone knows if there is any reporting solution for silverlight(Like Crystal Reports).
|
|
|
|
|
Well, Google[^] returns a fair few hits."WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Hi.
I stoped with the reporting with silverlight because know i'm working on something else.
As soon i have results, i'll send you the results.
Thanks for the tip
|
|
|
|
|
|
hi.
thanks for the tip.
As soon i get results i'll tell you.
Regards.
|
|
|
|
|
Say, if the TreeView control is 200px width and the TreeViewItem's width is more than 200px, I need to show the tooltip. Is there a way to show tooltip on that scenario in WPF?
|
|
|
|
|
Hello
I have created a class inherits frameworkelement which i am using to graphically represent an object in my WPF project. My first attempt overrides the onRender method and draws a rectangle, using property's length and width.
I am doing this to reduce the overhead required for each object as i will have a number of these on the page at one time.
This works fine, now i want to do the same thing but draw a more complicated shape the path. I do not know where to start with this, has anyone attempted this before if so how did you do this??
Here is my working code for simple rectangle.
Protected Overrides Sub OnRender(ByVal drawingContext As System.Windows.Media.DrawingContext)
drawingContext.DrawRectangle(Status, New Pen, New Rect(0, 0, conveyorLength, conveyorWidth))
MyBase.OnRender(drawingContext)
End Sub
Thanks
|
|
|
|
|