Click here to Skip to main content
15,918,007 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: Third Party Controls Pin
Kevin Marois12-Dec-12 8:30
professionalKevin Marois12-Dec-12 8:30 
GeneralRe: Third Party Controls Pin
Mycroft Holmes12-Dec-12 12:02
professionalMycroft Holmes12-Dec-12 12:02 
QuestionHow can I Bind a DataTemplate Slider definition to the Code behind? Pin
maycockt10-Dec-12 5:24
maycockt10-Dec-12 5:24 
AnswerRe: How can I Bind a DataTemplate Slider definition to the Code behind? Pin
Alisaunder10-Dec-12 13:52
Alisaunder10-Dec-12 13:52 
GeneralRe: How can I Bind a DataTemplate Slider definition to the Code behind? Pin
maycockt14-Dec-12 1:18
maycockt14-Dec-12 1:18 
QuestionHow does one define IOleServiceProvider in a C# WPF application? Pin
Xarzu10-Dec-12 3:54
Xarzu10-Dec-12 3:54 
AnswerRe: How does one define IOleServiceProvider in a C# WPF application? Pin
Pete O'Hanlon10-Dec-12 4:08
mvePete O'Hanlon10-Dec-12 4:08 
QuestionSetting icons based on Region/city name?! Pin
radkrish9-Dec-12 19:43
radkrish9-Dec-12 19:43 
AnswerRe: Setting icons based on Region/city name?! Pin
Abhinav S9-Dec-12 20:12
Abhinav S9-Dec-12 20:12 
QuestionWPF ComboBox Selected Item Problem Pin
Kevin Marois8-Dec-12 10:48
professionalKevin Marois8-Dec-12 10:48 
AnswerRe: WPF ComboBox Selected Item Problem Pin
Ninja__Turtle8-Dec-12 17:43
Ninja__Turtle8-Dec-12 17:43 
AnswerRe: WPF ComboBox Selected Item Problem Pin
Wayne Gaylard8-Dec-12 18:24
professionalWayne Gaylard8-Dec-12 18:24 
GeneralRe: WPF ComboBox Selected Item Problem Pin
Kevin Marois8-Dec-12 19:37
professionalKevin Marois8-Dec-12 19:37 
GeneralRe: WPF ComboBox Selected Item Problem Pin
Kevin Marois8-Dec-12 19:37
professionalKevin Marois8-Dec-12 19:37 
GeneralRe: WPF ComboBox Selected Item Problem Pin
Wayne Gaylard8-Dec-12 19:39
professionalWayne Gaylard8-Dec-12 19:39 
QuestionAt commands Pin
Pranay Dabholkar7-Dec-12 5:56
Pranay Dabholkar7-Dec-12 5:56 
AnswerRe: At commands Pin
Abhinav S9-Dec-12 20:14
Abhinav S9-Dec-12 20:14 
QuestionCurrency Converter Pin
pjank427-Dec-12 5:44
pjank427-Dec-12 5:44 
AnswerRe: Currency Converter Pin
Pete O'Hanlon7-Dec-12 6:58
mvePete O'Hanlon7-Dec-12 6:58 
GeneralRe: Currency Converter Pin
pjank427-Dec-12 7:38
pjank427-Dec-12 7:38 
QuestionWPF Binding TextBox to Dependency Property Pin
g_ap5-Dec-12 1:02
g_ap5-Dec-12 1:02 
AnswerRe: WPF Binding TextBox to Dependency Property Pin
Richard Deeming5-Dec-12 2:53
mveRichard Deeming5-Dec-12 2:53 
Questionhighlight list view - is--moueOver Pin
dominioYP3-Dec-12 10:07
dominioYP3-Dec-12 10:07 
AnswerRe: highlight list view - is--moueOver Pin
SledgeHammer013-Dec-12 11:52
SledgeHammer013-Dec-12 11:52 
QuestionWPF DrawingContext DrawText bug??? Pin
subakaev2-Dec-12 21:09
subakaev2-Dec-12 21:09 
I'm writing a program that construct a huge diagram. Also this diagram can be save to png file. I have no problems when I render my diagram on WPF canvas. The problem start when I trying save it to file. DrawingContext.DrawText stop drawing the text with size==10 when horizontal text position becomes more than 11K pixels!

Here is the code that shows this effect.

I create simple WPF application project and create one class (MainViewControl):

Here is the code for MainViewControl.cs:
C#
class MainViewControl : FrameworkElement
    {
        public void Draw(DrawingContext context)
        {
            for (var i = 0; i < Width / 100; i++)
            {
                var text = new FormattedText((i * 100).ToString(CultureInfo.InvariantCulture), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Verdana"), 10, Brushes.Blue);
                var textPos = new Point((double)i * 100f + 0.789 - text.Width / 2, Height / 2 - text.Height / 2);
                context.DrawLine(new Pen(Brushes.Red, 1.0), new Point(i * 100, 0), new Point(i * 100, Height));
                context.DrawRectangle(Brushes.White, null, new Rect(textPos.X, textPos.Y, text.Width, text.Height));
                context.DrawText(text, textPos);
            }
        }

        protected override void OnRender(DrawingContext context)
        {
            Draw(context);
        }
    }
Here is the code for MainWindow.xaml:
C#
 <Window x:Class="DrawTextProblem.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:DrawTextProblem="clr-namespace:DrawTextProblem"
        Title="MainWindow" >
    <DockPanel>
        <Button Content="Save" Click="ButtonClick" DockPanel.Dock="Top" HorizontalAlignment="Left" />
        <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" DockPanel.Dock="Top">
            <DrawTextProblem:MainViewControl Width="50000" Height="200" x:Name="mainViewControl" />
        </ScrollViewer>
    </DockPanel>
</Window> 

When click the button I do this:
C#
private void ButtonClick(object sender, RoutedEventArgs e)
       {
           var dlg = new Microsoft.Win32.SaveFileDialog { FileName = "Image", DefaultExt = ".png", Filter = "Images (.png)|*.png" };

           if (dlg.ShowDialog() == true)
           {
               try
               {
                   var bounds = new Rect(0, 0, mainViewControl.Width, mainViewControl.Height);
                   var diagramBitmap = new RenderTargetBitmap((int)bounds.Width, (int)bounds.Height, 96d, 96d, PixelFormats.Default);

                   var drawingVisual = new DrawingVisual();
                   var context = drawingVisual.RenderOpen();
                   context.DrawRectangle(Brushes.White, null, bounds);
                   mainViewControl.Draw(context);
                   context.Close();

                   diagramBitmap.Render(drawingVisual);

                   var imageFile = new FileStream(dlg.FileName, FileMode.Create, FileAccess.Write);

                   var encoder = new PngBitmapEncoder();
                   encoder.Frames.Add(BitmapFrame.Create(diagramBitmap));
                   encoder.Save(imageFile);
                   imageFile.Flush();
                   imageFile.Close();

                   MessageBox.Show("Image successfully saved.", "Image saved", MessageBoxButton.OK, MessageBoxImage.Information);
               }
               catch (Exception exception)
               {
                   MessageBox.Show(string.Format("Error:\n{0}", exception.Message), string.Empty, MessageBoxButton.OK, MessageBoxImage.Error);
               }
           }
       }

When I start this application I see MainViewControl on the MainWindow with all text labels every 100 pixels. If I click save button, text labels are disappearing in saved image after 11K pixels!

It's the same for text size = 10, 11 or 7, BUT not for 8, 9, 16 etc. Moreover, If I use text size 10.001 it works fine!

Does anybody know about this problem? It's a WPF bug?

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.