|
The issue you see here is that the WPF RichTextBox is unlike any MS RichTextBox released before it. It doesn't actually support RTF directly, so you need to perform a little trick which is to use the TextRange and save to a MemoryStream. Here's a couple of handly little extension methods you can use:
public static string FormattedSave(this RichTextBox rtb)
{
return FormattedSave(rtb, System.Windows.DataFormats.Rtf);
}
public static string FormattedSave(this RichTextBox rtb, System.Windows.DataFormat dataFormat)
{
TextRange range = new TextRange(rtb.Document.ContentStart, rtb.Document.ContentEnd);
using (MemoryStream ms = new MemoryStream())
{
range.Save(ms, dataFormat);
string retVal = ASCIIEncoding.Default.GetString(ms.ToArray());
ms.Close();
return retVal;
}
}
|
|
|
|
|
i tried your code but when i assign retVal to mailItem.Body it is filled with content like
"{\rtf1\ansi\ansicpg1252\uc1\htmautsp\deff2{\fonttbl{\f0\fcharset0 Times New Roman;}{\f2\fcharset0 Segoe UI;}{\f3\fcharset0 Calibri;}{\f4\fcharset0 Courier New;}{\f5\fcharset2 Symbol;}{\f6\fcharset0 Arial;}}{\colortbl\red0\green0\blue0;\red255\green255\blue255;\red0\green255\blue255;\red255\green255\blue0;\red31\green73\blue125;\red54\green95\blue145;}\loch\hich\dbch\pard\plain\ltrpar\itap0{\lang1033\fs18\f2\cf0 \cf0\ql{\fs22\f3 {\ltrch Dear Supplier,}\li0\ri0\sa0\sb0\fi0\ql\par}"
|
|
|
|
|
Yup. That's RTF - which is what gets displayed properly when you display rich text format. To test it, take this text and save it in a file that ends with the extension rtf. Then open it up in Wordpad.
|
|
|
|
|
Yes when i open it after giving it rtf extension it shows correct content but what i want to do is create a mail using this content.
|
|
|
|
|
I want to update the display of a TreeView during runtime with new data. All data is stored in a collection which is assigned to the TreeView's ItemsSource.
This works fine first time when the TreeView is empty. But second time it doesn't.
tvTree.ItemsSource = root.Branches;
Later after stored more data in the collection root.Branches
tvTree.ItemsSource = root.Branches;
My XAML code:
<Window x:Class="Tree.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:node="clr-namespace:Tree.TreeNodes"
Title="MainWindow" Height="350" Width="525">
<Grid>
<TreeView Name="tvTree" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="5,5,0,0" Width="400" Height="500">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Branches}" DataType="{x:Type node:Node}">
<Grid>
<TextBlock Text="{Binding Header}" />
</Grid>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
</Grid>
</Window>
The "node" namespace reference, "Branches" in ItemsSource and "Header" in the TextBlock refers to the collection where the data is stored. I guess it's right because the TreeView populates data first time.
Any suggestions?
|
|
|
|
|
Make sure that you bind to an ObservableCollection, and your UI will update based on changes to the collection. This means that you don't have to drop and reassign bindings.
|
|
|
|
|
I don't really get it. I changed the root.Branches from Dictionary<string, branch=""> collection to ObservableCollection<branch> which was not fun. But still nothing happens.
Can you give me small a code example in C# and XAML which works, please?
|
|
|
|
|
Ok, a few clarifications:
1) in your original post you did something like:
treeView.ItemsSource = blah;
and then tried to do:
treeView.ItemsSource = blah;
again later. Not sure if that is a typo or not, but you can't reassign the same list like that because ItemsSource is a dependency property, so the tree view will only respond to CHANGE notifications.
You could do:
treeView.ItemsSource = blah;
treeView.ItemsSource = null;
treeView.ItemsSource = blah;
and it will work, but that is not the right solution.
Pete's response for you to switch over to an ObservableCollection wasn't a great response (and it was incomplete) because as you saw, it took a lot of code changes on your part. It would have been easier to switch you over to ObservableDictionary. This is not part of .NET (yet), but it was published on Dr. WPF's blog several years ago. It is WIDELY used.
2) Switching you over to an observable collection class was only half the solution. That will allow the tree to respond to your adding and removing items, but not changing items themselves. For that, your item class needs to implement INotifyPropertyChanged.
modified on Monday, August 8, 2011 12:40 PM
|
|
|
|
|
I saw the comment typo, darn it. Well you understood it correct
I tried this way:
treeView.ItemsSource = blah;
treeView.ItemsSource = null;
treeView.ItemsSource = blah;
I can see the ItemsSource is changed in debug, but it's already changed before the null is passed into it (I guess that is due to .NET reference mechanism). However the visualization of the TreeView did not change. It's same as when I set ItemsSource the first time.
The root.Branches, which I pass into ItemsSource, is a complex set of classes which is used to store all data that the TreeView should display. I tried with a easier application with a simpler collection of data and then the method works. Very strange!
Any suggestions?
|
|
|
|
|
Created a business application that populates a datagrid form SQL2K8. Using WCF-RIA services. The app works fine. Today I decided to add three more columns to the existing table(used data type varchar(50) and INT ). I updated the SL project as follows:
1. Deleted the XXXDomainServices
2. Deleted the XXXXMetadata
3. Deleted the XXX.edms
4. Recreated the files and compiled the solution
The problem is when I ran the application, the new column names appeared in the datagrid but no data. All the new columns are empty. Looking directly in the SQL2K8 server, the columns are populated with correct values.
Any help is greatly appreciated
|
|
|
|
|
Hi,
what is the best model for using services in a silverlight application?
I usualy add a wcf service to my ASP.net app and add a service refrence to my silverlight application, but anytime I change my service I should update the service refrence in silverlight app.
Is there any better and more proffessional way?
Best wishes
|
|
|
|
|
mehrdadc48 wrote: Is there any better and more proffessional way
I'm gonna be interested in reponses to this one, I see no other alternative to updating the service reference whenever you change the service.
I do take exception to having my method called unprofessional
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
If you can reference an assembly with your service interface and any types you might use. Then you can use the ChannelFactory
ChannelFactory factory = new ChannelFactory<IService>()
IService myService = factory.CreateChannel();
myService.Foo();
the drawback is you don't have any auto generated code so if you need asynchronous calls then you'll have to write that yourself.
If you need the auto generated code, then I suppose you could use svcutil in the post build event of your service project.
eg.
svcutil "http://localhost:1892/IMyService.svc" /out:OutputDir\MyService.cs
This however requires that you have an ISS running with a site that has your service's output directory as it's Content directory.
Also you proporbly have some kind of source control so you might want to add some lines before the above line so that MyService.cs is checked out before svcutil overwrites it.
That's the only two way I know of to avoiding having to update the service reference.
|
|
|
|
|
All this b/c the OP does not like the auto generated code. Not a chance, I have no problem using the auto code, I know what it does, I understand how it works and I have absolutely no interest in circumventing the MS methodology.
The only time I can justify chucking this type of auto generated code is if the code is flaky or it needs to be extended for some reason, so far this has not been the case!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote: I have absolutely no interest in circumventing the MS methodology
I don't see how either of those two methods is circumventing the MS methodology.
When you press Update Service Reference it's svcutil that is being used.
Using the ChannelFactory is what I personally use when I control both the server and the client. My primary reasons for this is; I don't have to update anything(Service reference) and I'm not limited to using DTO's.
While converting a project from using the auto generated proxy to using the ChannelFactory may very well be a waste of time. I do still beleave my other suggestion (using the svcutil) is easy to do and would work.
|
|
|
|
|
I work for a defense contractor, and all of our web sites require smartcards in order to access them. To make matters worse, after a given amount of time of inactivity, the user's PIN must be re-entered before you can continue using the web site. We we were contemplating moving our web sites over to Silverlight4, but we're not sure how to proceed given the smartcard requirement.
I know we can use an aspx web site to allow access to a silverlight app, but the inactivity aspect is not so clear. Has anyone here done a silverlight app in a similar environment (US DoD contractor) that's controlled with a smartcard?
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
We implement a timeout and log the user off if there is no activity through the navigate method. If some poor bastard needs to sit and stare at a single page for more that 20 minutes then thats just tough, they are out of there.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi all,
I need to build TreeViewItems dynamically in Silverlight4, C#.net, Visual Studio 2010 Premium.
Currently the TreeView consists of only a lot of TextBlocks, and I need to put a CheckBox in front of each TextBlock dynamically. This has to be done in code-behind, not in the xaml.
I have done a few Google searches, but could not find anything that I could use to guide me to do this.
Please provide me with links to articles/demos/discussions/etc that will help me.
Some code snippits would be appreciated too...
Thanks
modified on Friday, August 5, 2011 7:45 AM
|
|
|
|
|
You should explain what you are trying to do. Telling us you need to dynamically build a UI from the code behind sounds like you are headed down the wrong path. I just wrapped up a customized TreeView that I wrote that does exactly what you are talking about... added checkbox and image support to the stock WPF TreeView. None of my code involves dynamically building the UI from the code behind. Its all in XAML via triggers, etc.
|
|
|
|
|
Done in XAML via triggers?
I have never heard of triggers in XAML.
What is it, and how are they used?
But I guess that's for another thread, huh.
I'll Google it...
|
|
|
|
|
Sledge has got it right, if you are using code to create a UI element you are doing it WRONG. Build you template in xaml with a stackpanel containing a checkbox and a textblock, bind them to your data collection. Your data collection may be manipulated from the code but not your UI element.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thanks for the replies.
Additional Info: The UserControl that contains the TreeView is used on another page too, but NOT with the CheckBox. The functionality there requires the user to actually select the appropriate TreeViewItem. In the new scenario, the TreeView is be populated with exactly the same data is on the other page, but with the additional CheckBox for each TreeViewItem where the user is allowed to select multiple CheckBoxes in the TreeView. My idea was to just add the CheckBox to each TreeViewItem dynamically as each is built, and before it is added to the TreeViewItems collection.
Question: Should I put another grid in my XAML with exactly the same methods etc as for the original TreeView, but with the additional CheckBox as part of the TreeViewItemTemplate?
Then whenever this altered TreeView is needed, I toggle the visibility of the 2 grids in my XAML?
Thanks again for any directional advice and alternative suggestions.
|
|
|
|
|
Hi all,
This is how I did it.
I hope it helps someone in the future.
Microsoft.Windows.Controls.TreeViewItem treeitem = new Microsoft.Windows.Controls.TreeViewItem();
StackPanel sp = new StackPanel();
sp.Orientation = Orientation.Horizontal;
CheckBox cb = new CheckBox();
sp.Children.Add(cb);
sp.Children.Add(treeitem);
|
|
|
|
|
Hallo!
I developed a game for Windows Phone 7 (myStraights).
During the game you are able to enter numbers. I'm not satisfied with the solution I have.
The buttons are simple WPF buttons without
further change. I'm searching for a solution for following problem, maybe someone can help me:
I tried to create a virtual keyboard (but just with numeric values) like
the original virtual keyboard of the Windows Phone 7 (the original keyboard takes up too much space). When a button is pressed and somebody is moving his/her finger to another
button, the button raises the Mouse_Leave event and on the other button the Mouse_Enter event.
On the first button the Mouse_LeftButtonDown event occures. When you're leaving the original
button, the Mouse_LeftButtonUp event doesn't occure on another button when raising the finger, that's okay
What I did: In code I remember which button was the last "Mouse_Enter" button, when leaving the button and leaving the container of the button. Maybe the player wanted to press this button, but this is not for sure. The last position of the finger (observed throw the MouseMove event) is not reliable. I'm searching a method to determine whether the finger was over a button at the time on which the user raised the finger.
Thanks in advance, many greetings,
Thomas
|
|
|
|
|
hi i'm a wpf beginner and i have some question i was hoping that you may help me .
I'm developping a wpf project using MvvM light for WPF4 toolkit but I don't seem to make a connection with my SQL data base , I tried to do a databinding using ADO.net entity framework but it doesn't provide me class for each table, same thing for the methode Link to SQL ,
so I'm wondering what is the appropriate way to do a databinding that transform each table in my database to a class (as the model layer for the design pattern MvvM ) so i can manipulate it .
thanks for your concern and I hope you can really help me cause I'm totally clueless !
|
|
|
|