<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Jefim Borissov &#187; WPF</title>
	<atom:link href="http://jefim.eu/blog/category/it/programming/wpf/feed/" rel="self" type="application/rss+xml" />
	<link>http://jefim.eu/blog</link>
	<description>Житие мое</description>
	<lastBuildDate>Sun, 11 Jul 2010 07:52:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Localizing a WPF application</title>
		<link>http://jefim.eu/blog/2010/03/localizing-a-wpf-application/</link>
		<comments>http://jefim.eu/blog/2010/03/localizing-a-wpf-application/#comments</comments>
		<pubDate>Fri, 19 Mar 2010 20:15:18 +0000</pubDate>
		<dc:creator>Jefim</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://jefim.eu/blog/?p=304</guid>
		<description><![CDATA[I know, Google knows so much about this, yet still, no clear and simple step-by-step guide. So here it goes: Download LocBaml tool here Compile it and get the LocBaml.exe Open your project file with Notepad. Add the following there: &#60;UICulture&#62;en-US&#60;/UICulture&#62; under all &#60;PropertyGroup&#62; tags (for all build configs that is). In your XAML files [...]]]></description>
			<content:encoded><![CDATA[<p>I know, Google knows so much about this, yet still, no clear and simple step-by-step guide. So here it goes:</p>
<ul>
<li>Download LocBaml tool <a title="LocBaml" href="http://msdn.microsoft.com/en-us/library/ms771568.aspx" target="_blank">here</a></li>
<li>Compile it and get the LocBaml.exe</li>
<li>Open your project file with Notepad.</li>
<li>Add the following there: <strong>&lt;UICulture&gt;en-US&lt;/UICulture&gt;</strong> under all &lt;PropertyGroup&gt; tags (for all build configs that is).</li>
<li>In your XAML files add <strong>x:Uid="someUniqueUid"</strong> to any element you want to localize.</li>
<li>Build your project.</li>
<li>Navigate your explorer to the build folder - you will see that it has a new subfolder called <strong>en-US</strong>. Inside you will find a file - <strong>YourProject.resources.dll</strong></li>
<li>Copy the binary of your project (e.g. YourProject.exe), LocBaml.exe and any referenced project binaries into this en-US folder.</li>
<li>Open a command line prompt in this folder (under Windows seven you can press <em>[Shift] + Right click <span style="font-style: normal;">and choose the command prompt window from the context menu).</span></em></li>
<li><em><span style="font-style: normal;">Run the following: <strong>locbaml /parse YourProject.resources.dll /out:YourProject.txt </strong>- a human-readable text file will appear in the folder.</span></em></li>
<li><em><span style="font-style: normal;">Edit the text file (translate the values in it). Excel is your best option - open the file from Excel menu and it will ask you if you want to treat tab symbols as text separators).</span></em></li>
<li>Run the following after you localized the text file: <strong>locbaml /generate /trans:YourProject.txt /out:..\ru-RU /cul:ru-RU YourProject.resources.dll </strong>(replace ru-RU with the culture you are localizing into).</li>
<li>Now all you have to do is to set the CultureInfo for your application thread like this:</li>
</ul>
<pre class="csharp" name="code">var cultureInfo = new CultureInfo("ru-RU");
System.Threading.CurrentThread.CurrentCulture = cultureInfo;
System.Threading.CurrentThread.CurrentUICulture = cultureInfo;</pre>
<p>And you are done. You app should be localized now!</p>
]]></content:encoded>
			<wfw:commentRss>http://jefim.eu/blog/2010/03/localizing-a-wpf-application/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>HOW-TO: Creating a simple UserControl for displaying a FlowDocument</title>
		<link>http://jefim.eu/blog/2007/09/how-to-creating-a-simple-usercontrol-for-displaying-a-flowdocument/</link>
		<comments>http://jefim.eu/blog/2007/09/how-to-creating-a-simple-usercontrol-for-displaying-a-flowdocument/#comments</comments>
		<pubDate>Wed, 12 Sep 2007 07:11:08 +0000</pubDate>
		<dc:creator>Jefim</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://jefim.wordpress.com/2007/09/12/how-to-creating-a-simple-usercontrol-for-displaying-a-flowdocument/</guid>
		<description><![CDATA[Hello. This is my first post about WPF. This how-to will show you how to create a UserControl in which you can show a FlowDocument by passing a string containing the FlowDocument. It also allows Data Binding. Lets start. 1. Create a UserControl called FlowDocumentViewer in Expression Blend (you can also do this in Visual [...]]]></description>
			<content:encoded><![CDATA[<p>Hello. This is my first post about WPF.</p>
<p>This how-to will show you how to create a UserControl in which you can show a FlowDocument by passing a string containing the FlowDocument. It also allows Data Binding.</p>
<p>Lets start.</p>
<p>1. Create a UserControl called FlowDocumentViewer in Expression Blend (you can also do this in Visual Studio if you want) and add a FlowDocumentScrollViewer to LayoutRoot. Name it <strong>flowDocument</strong> (you can name it like you want, but I will be using this name in this guide). Your structure should be as follows:</p>
<p align="center"><img src="http://jefim.files.wordpress.com/2007/09/screen1.jpg" alt="Structure" border="1" /></p>
<p>2.  Now, open the project in Visual Studio and add the following code to your FlowDocumentViewer.xaml.cs:</p>
<pre>        public static readonly DependencyProperty ContentFlowDocumentStringProperty = DependencyProperty.Register(
            "ContentFlowDocumentString",
            typeof(string),
            typeof(FlowDocumentViewer),
            new FrameworkPropertyMetadata(null,
                FrameworkPropertyMetadataOptions.AffectsRender,
                new PropertyChangedCallback(DescriptionFlowDocumentUI.OnContentChanged)
            )
        );

        private static void OnContentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            FlowDocumentViewer control = (FlowDocumentViewer)d;
            control.flowDocument.Document =
                (System.Windows.Documents.FlowDocument)System.Windows.Markup.XamlReader.Load(
                    new MemoryStream(System.Text.UTF8Encoding.Default.GetBytes((string)e.NewValue))
                );
        }

        public string ContentFlowDocumentString
        {
            get { return (string)GetValue(ContentFlowDocumentStringProperty); }
            set { SetValue(ContentFlowDocumentStringProperty, value); }
        }</pre>
<p>Lets see what this code does.</p>
<p>a) We added a <em>DependencyProperty</em> called <em>ContentFlowDocumentStringProperty</em> to our class. This <em>DependencyProperty</em> "points" at <em>ContentFlowDocumentString</em> property, as well as it tells, that this property of type <em>string</em> and we registered a callback function (<em>OnContentChanged</em>), which will be triggered when ContentFlowDocumentString is changed. Note that <em>FrameworkPropertyMetadataOptions.AffectsRender</em> piece of code. This tells WPF, that when this property is changed it affects the UI looks, so that WPF knows he has to render something.</p>
<p>b) The <em>OnContentChanged</em> function is called whenever our DependencyProperty is changed. Here we do the actual work of changing the FlowDocument in our control. We get the instance as an argument (<em>DependencyObject d</em>, which we cast to FlowDocumentViewer explicilty) and we create a new FlowDocument from the newly assigned string (<em>(string)e.newValue</em>).</p>
<p>c) Finally we added the actual property - ContentFlowDocumentString. See those <em>GetValue</em> and <em>SetValue</em>? Don't be surprized, it is how DependencyProperties work. You don't have a special (private) field in your class for them. WPF does all the work for you.</p>
<p>Well, that is pretty much it.</p>
<p>The usage is simple:</p>
<pre>FlowDocumentViewer fdv = new FlowDocumentViewer();
fdv.ContentFlowDocumentString = stringContainingFlowDocumentXAML;</pre>
<p>Or if you want to use data binding, it is absolutely similar to casual binding in WPF:</p>
<pre>Binding b = new Binding();
b.Source = myBindingSource;
b.Path = new PropertyPath("PathToProperty");
FlowDocumentViewer fdv = new FlowDocumentViewer();
fdv.SetBinding(FlowDocumentViewer.ContentFlowDocumentStringProperty, b);</pre>
<p>If you have questions / remarks / etc. feel free to post them. I will try to answer.</p>
]]></content:encoded>
			<wfw:commentRss>http://jefim.eu/blog/2007/09/how-to-creating-a-simple-usercontrol-for-displaying-a-flowdocument/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
