I have a situation in which i need to create a user control that hosts a content presenter. Now, the content presenter should be using the template to display data.
I have designed a user control as follows. xaml
<UserControl x:Class="Dashboard.ComponentStatisticsControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
Name="SatisticsControl"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Label Content="{Binding ElementName=SatisticsControl, Path=Title}"
Grid.Row="0"
Background="SkyBlue"/>
<ContentPresenter Content="{Binding ElementName=SatisticsControl, Path=AdditionalContent}"
Grid.Row="1"/>
</Grid>
</UserControl>
Now i have a WrapPanel defined in my MainWindow.xaml that should host the ComponentStatisticsControl
<Window x:Class="Dashboard.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Dashboard"
Height="350" Width="525"
ShowInTaskbar="True"
WindowState="Maximized"
WindowStyle="None"
Name="_this">
<Window.Resources>
<LinearGradientBrush x:Key="PanelBackground"
StartPoint="0, 1"
EndPoint="1, 0">
<GradientStop Color="SkyBlue" Offset="0.3"/>
<GradientStop Color="PaleGreen" Offset="1"/>
</LinearGradientBrush>
<SolidColorBrush x:Key="BorderBrush"
Color="Blue"/>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0">
<Button Click="Button_Click"
HorizontalAlignment="Left"
VerticalAlignment="Center">Click</Button>
</StackPanel>
<WrapPanel Name="WrapPanelMain"
Orientation="Horizontal"
FlowDirection="LeftToRight"
Grid.Row="1">
</WrapPanel>
</Grid>
</Window>
Now i am creating the content for the ComponentStatisticsControl in code behind.
public void CreateComponent(ref DiscoveryMessage Message)
{
switch (Message.Identifier)
{
case ComponentIdentifier.Dispatcher:
{
ComponentStatisticsControl StatisticsControl = new ComponentStatisticsControl();
StatisticsControl.Title = "Dispatcher";
StatisticsControl.AdditionalContent = new Label() { Content = "Hello"};
WrapPanelMain.Children.Add(StatisticsControl);
break;
}
}
}
However, i can not see the data added. What did i miss out. I have spent much time banging about what went wrong.
I should be able to see the content set for the label "Hello" in the WrapPanel.
public class DispatcherStatistics
{
private uint f_QCount;
public uint QueueCount { get { return f_QCount; }
set
{
f_QCount = value;
}
}
}
I will be setting this class instance to the AdditionalContent. So that QueueCount will be updated whenever i assign a new instance of this class.
Thanks in advance
EDIT
I was getting the text of my class type in the wrap panel. Now the above problem is solved, but how can i define a template for the content to show.
public void CreateComponent(ref DiscoveryMessage Message)
{
1switch (Message.Identifier)
{
case ComponentIdentifier.Dispatcher:
{
ComponentStatisticsControl StatisticsControl = new ComponentStatisticsControl();
StatisticsControl.Title = "Dispatcher";
StatisticsControl.AdditionalContent = f_clDispatcherStatistics;
WrapPanelMain.Children.Add(StatisticsControl);
break;
}
}
}
f_clDispatcherStatistics is a private instance variable for DispatcherStatistics class
This is displaying "Dashboard.DispatcherStatistics"
I want to display something like
QueueCount : 0
like this format.
You are doing it a little complicated. You can use the Content property of UserControl directly.
Here is the important part of the template (using the default ContentPresenter):
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Label Content="{Binding ElementName=SatisticsControl, Path=Title}"
Grid.Row="0"
Background="SkyBlue"/>
<ContentPresenter Grid.Row="1"/>
</Grid>
And then use the Content property directly:
ComponentStatisticsControl StatisticsControl = new ComponentStatisticsControl();
StatisticsControl.Title = "Dispatcher";
StatisticsControl.Content = new Label() { Content = "Hello"};
WrapPanelMain.Children.Add(StatisticsControl);
Related
I have always been using MVVM model when creating applications with WPF and everything connected with displaying/modifying Bitmaps worked well, however this time I have decide to choose other way as I want to adjust Bitmap width and height to the control that should contain it, but something doesn't work here.
I use an event that is executed on Load as I want to get the actual height and width as said before.
Part of my code:
private BitmapImage scene;
public BitmapImage Scene
{
get { return scene; }
set { if (scene != value) { scene = value; RaisePropertyChanged("Scene"); } }
}
public MainWindow()
{
InitializeComponent();
this.DataContext = this;
LoadSceneCommand = new RelayCommand(LoadScene);
GenerateTexturedCylinderCommand = new RelayCommand(GenerateTexturedCylinder);
GenerateTexturedSphereCommand = new RelayCommand(GenerateTexturedSphere);
GenerateCylinderShadingCommand = new RelayCommand(GenerateCylinderShading);
GenerateSphereShadingCommand = new RelayCommand(GenerateSphereShading);
}
private void GetSceneSize(object sender, RoutedEventArgs e)
{
object wantedNode = (Grid)this.FindName("SceneGrid");
if (wantedNode is Grid)
{
Grid imageControl = wantedNode as Grid;
sceneWidth = (int)imageControl.ActualWidth;
sceneHeight = (int)imageControl.ActualHeight;
try
{
PrepareScene();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
private void PrepareScene()
{
Bitmap bitmap = new Bitmap(sceneWidth, sceneHeight);
for (int x = 0; x < sceneWidth; ++x)
for (int y = 0; y < sceneHeight; ++y)
bitmap.SetPixel(x, y, Color.Black);
Scene = ImageConverters.Bitmap2BitmapImage(bitmap);
}
Xaml:
<Window x:Class="_3DRendering.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Loaded="GetSceneSize"
ResizeMode="NoResize"
Title="MainWindow" Height="450" Width="800">
<Window.Resources>
</Window.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="10"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="10"/>
<RowDefinition Height="*"/>
<RowDefinition Height="10"/>
</Grid.RowDefinitions>
<Grid Grid.Column="1" Grid.Row="1" x:Name="SceneGrid">
<Image Source="{Binding Scene}" x:Name="ImageControl"/>
</Grid>
<ScrollViewer Grid.Column="3" Grid.Row="1" VerticalScrollBarVisibility="Auto">
<StackPanel>
<StackPanel.Resources>
<Style TargetType="Button">
<Setter Property="Margin" Value="0 10 0 0"/>
<Setter Property="Padding" Value="5 5 5 5"/>
</Style>
</StackPanel.Resources>
<Button Content="Textured cylinder" Command="{Binding GenerateTexturedCylinderCommand}"/>
<Button Content="Textured sphere" Command="{Binding GenerateTexturedSphereCommand}"/>
<Button Content="Cylinder shading" Command="{Binding GenerateCylinderShadingCommand}"/>
<Button Content="Sphere shading" Command="{Binding GenerateSphereShadingCommand}"/>
<Button Content="Load Scene" Command="{Binding LoadSceneCommand}"/>
<Button Content="Save Scene" Command="{Binding }"/>
</StackPanel>
</ScrollViewer>
</Grid>
As you can see I try to make the whole Bitmap black. Unfortunately the result that I get is that nothing is displayed. It is just a blank white space in the place where my Bitmap should be shown.
I'm using exactly this Hamburger menu example
https://jkarger.de/2017/02/06/mahapps-hamburgermenu/
This works fine as long the views have the default constructor.
However I need to pass an object from the MetroWindow, where the Hamburger menu is implemented, to a UserControl called by clicking a menu item.
The XAML code for the menu item is like this.
<controls:HamburgerMenu.ItemsSource>
<controls:HamburgerMenuItemCollection>
<controls:HamburgerMenuGlyphItem Glyph="" Label="Home">
<controls:HamburgerMenuGlyphItem.Tag>
<views:main />
</controls:HamburgerMenuGlyphItem.Tag>
</controls:HamburgerMenuGlyphItem>
<controls:HamburgerMenuGlyphItem Glyph="" Label="Private">
<controls:HamburgerMenuGlyphItem.Tag>
<views:private />
</controls:HamburgerMenuGlyphItem.Tag>
</controls:HamburgerMenuGlyphItem>
<controls:HamburgerMenuGlyphItem Glyph="" Label="Settings">
<controls:HamburgerMenuGlyphItem.Tag>
<views:settings />
</controls:HamburgerMenuGlyphItem.Tag>
</controls:HamburgerMenuGlyphItem>
</controls:HamburgerMenuItemCollection>
</controls:HamburgerMenu.ItemsSource>
For instance the "main" view.
<controls:HamburgerMenuGlyphItem.Tag>
<views:main />
</controls:HamburgerMenuGlyphItem.Tag>
This is the constructor of my "main" UserControl.
#region PUBLIC_PROPERTIES
TesterConfig.TesterConfig tc;
#endregion
public main(TesterConfig.TesterConfig configuration)
{
InitializeComponent();
tc = configuration;
}
XAML for the "main" UserControl"
<UserControl x:Class="TestsystemConfiguration.Views.main"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
xmlns:local="clr-namespace:TestsystemConfiguration.Views"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid x:Name="gridMain">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="130"/>
<ColumnDefinition Width="423*"/>
<ColumnDefinition Width="175"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="70"/>
<RowDefinition Height="8"/>
<RowDefinition Height="36"/>
<RowDefinition Height="36"/>
<RowDefinition Height="36"/>
<RowDefinition Height="11*"/>
<RowDefinition Height="45*"/>
<RowDefinition Height="40"/>
</Grid.RowDefinitions>
<Image x:Name="imageLogo" Grid.Column="2" Source="pack://siteoforigin:,,,/Resources/logo.png" Margin="5" Grid.RowSpan="1"/>
<ComboBox x:Name="cbWorkingStation" IsEnabled="False" Grid.Column="1" Margin="5,2,10,2" Grid.Row="2" SelectionChanged="cbWorkingStation_SelectionChanged"/>
<Button x:Name="btnOpenDocs" Content="Doku öffnen" Style="{StaticResource AccentedSquareButtonStyle}" Grid.Column="2" Margin="5" Grid.Row="7" Controls:ControlsHelper.ContentCharacterCasing="Upper"/>
<Label Content="Arbeitsplatz:" Grid.Row="2" FontWeight="Bold"/>
</Grid>
</UserControl>
The "TesterConfig" is an object in my project and declared in the parent MetroWindow. How can I pass the reference to the UserControl?
Thanks for your help!
Thanks #mm8.
According to your suggestions I did it this way.
XAML (MenuItem)
<Controls:HamburgerMenuGlyphItem Glyph=""
Label="Home"
Tag="main">
</Controls:HamburgerMenuGlyphItem>
C# Code:
private void MenuControl_ItemClick(object sender, ItemClickEventArgs e)
{
HamburgerMenuGlyphItem i = e.ClickedItem as HamburgerMenuGlyphItem;
if(i != null)
{
UserControl uc = new UserControl();
switch(i.Tag.ToString())
{
case "main":
uc = new Views.main(tc);
break;
case "testsystems":
uc = new Views.testsystems();
break;
}
i.Tag = uc;
this.MenuControl.Content = i;
}
}
I created a switch depending on the tag.
Thanks for your help!
Best,
Andy
I am trying to show a rdlc report inside a user control. The problem is that it does not show when I run the project.
Before running the project I can see it in xaml designer.
After Running project:
Here is my code:
Report User Control:
<UserControl x:Class="CPOSApplication.UserControls.Reports.ReportViewer"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" Background="#FFFFFFFF"
xmlns:repview="clr-namespace:Microsoft.Reporting.WinForms;assembly=Microsoft.ReportViewer.WinForms">
<Grid>
<WindowsFormsHost x:Name="winform" Background="White" Visibility="Visible">
<repview:ReportViewer BackColor="white" x:Name="salesReportViewer"/>
</WindowsFormsHost>
</Grid>
Another UserControl where it is being used:
<UserControl x:Class="CPOSApplication.UserControls.Reports.SalesReport"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:uc="clr-namespace:CPOSApplication.UserControls.Reports"
mc:Ignorable="d"
d:DesignHeight="800" d:DesignWidth="900">
<Grid Style="{DynamicResource GridsCustomStyle}" x:Name="SearchShelfGri">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition MinWidth="100" />
</Grid.ColumnDefinitions>
<Border Grid.ColumnSpan="2" Style="{DynamicResource SearchGridHeaderBorder}">
<DockPanel Grid.Row="0">
<Label x:Name="GridLabel" Style="{DynamicResource HeadingLabelsCustomStyle}" Content="Sales Report-:"/>
</DockPanel>
</Border>
<uc:ReportViewer x:Name="salesReport" Grid.Column="0" Background="White" Grid.Row="1" Margin="0,0"/>
<uc:FilterSalesReport x:Name="filterShelf" Grid.Column="1" Grid.Row="1" Background="AliceBlue" Width="300" Padding="2,0,0,0" Margin="0,0"/>
</Grid>
It's .cs File
public partial class SalesReport : UserControl
{
public SalesReport()
{
InitializeComponent();
salesReport.salesReportViewer.ProcessingMode = ProcessingMode.Local;
salesReport.salesReportViewer.LocalReport.ReportPath = #"C:\Users\Safi\Documents\Visual Studio 2012\Projects\CPOS\CPOS\CPOSApplication\Reports\QuarterSaleInvoiceReport.rdlc";
salesReport.salesReportViewer.RefreshReport();
salesReport.salesReportViewer.LocalReport.ReportEmbeddedResource = "CPOSApplication.Reports." + ReportType.QuarterSaleInvoice.ToString() + "Report.rdlc";
salesReport.salesReportViewer.RefreshReport();
}
}
//in your CS file, create this method
public void GenReport()
{
YourReportViewfname.LocalReport.ReportPath = #"paste Your RDLC Location";
YourClass rptclsProp01 = new YourClass();
var data = rptclsProp01.YourList();
ReportDataSource dataSource = new ReportDataSource("YourDataSet", data);
YourReportViewfname.LocalReport.DataSources.Clear();
YourReportViewfname.LocalReport.DataSources.Add(dataSource);
YourReportViewfname.RefreshReport();
YourReportViewfname.Show();
}
//then Button Click event, just call the method
this.YourUCfnam.salesReport.GenReport();
//hope that report will show
hi i need to how can i make a overlay like page in xaml for windows phone ? Like, if i tap a button it will show a overlay like message loading... and then actually start to work. All i have been able to create a popup in xaml.
<Popup x:Name="myPopup" HorizontalAlignment="Center" VerticalAlignment="Center" >
<Grid >
<Grid.RowDefinitions>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock FontSize="25" Grid.Column="1" Margin="20" Text="loading"/>
</Grid>
</Popup>
Can you plz tell me how can make overlay like message ?
If you need and overlay there it is.
First you need an usercontrol.
<UserControl x:Class="ABC.Test.OverLay"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
d:DesignHeight="800" d:DesignWidth="480">
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="400"/>
<RowDefinition Height="400"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="1">
<ProgressBar IsIndeterminate="True" Foreground="Red" Height="80" Width="480" VerticalAlignment="Center"/>
<TextBlock Text="loading" Foreground="Red" HorizontalAlignment="Center" FontSize="20"/>
</StackPanel>
</Grid>
In Codebehind :
public OverLay()
{
InitializeComponent();
this.LayoutRoot.Height = Application.Current.Host.Content.ActualHeight;
this.LayoutRoot.Width = Application.Current.Host.Content.ActualWidth;
SystemTray.IsVisible = false;
}
In the page where you would show the overlay, create an instance of popup just like this:
private Popup popup;
Initialize it after InitializeComponent(),like this :
this.popup = new Popup();
on the event where you need the overlay to show up, try like this :
this.LayoutRoot.Opacity = 0.2;
OverLay _ovr = new OverLay();
this.popup.Child = _ovr;
this.popup.IsOpen = true;
BackgroundWorker _worker = new BackgroundWorker();
_worker.DoWork += (s, a) =>
{
//you can do your work here.
Thread.Sleep(3000);
};
_worker.RunWorkerCompleted += (s, a) =>
{
popup.IsOpen = false;
this.LayoutRoot.Opacity = 1.0;
};
_worker.RunWorkerAsync();
Find the working Here on Nokia Developers community
<Application
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="MultiLanguage.App"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary x:Name="LanguageDictionary" Source="/LanguageResources;component/EnglishResources.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
EnglishResources.xaml
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib">
<sys:String x:Key="add">ADD</sys:String>
<sys:String x:Key="key">Key</sys:String>
<sys:String x:Key="stringValue">String Value</sys:String>
MainWindow.xaml
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="MultiLanguage.MainWindow"
x:Name="Window"
Title="MainWindow"
Width="640" Height="480">
<Grid x:Name="LayoutRoot" HorizontalAlignment="Center" VerticalAlignment="Center">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Button x:Name="btnAdd" Content="{DynamicResource add}" Height="48" Grid.Column="0" Grid.Row="3" Grid.ColumnSpan="2" Margin="10" Click="btnAdd_Click" />
<TextBlock Text="{DynamicResource key}" Height="40" Width="100" Grid.Column="0" Grid.Row="0" Margin="10"/>
<TextBlock Text="{DynamicResource stringValue}" Height="40" Width="100" Grid.Column="0" Grid.Row="1" Margin="10"/>
<TextBox x:Name="txtKey" Height="40" Width="200" Grid.Column="1" Grid.Row="0" Margin="10"/>
<TextBox x:Name="txtStringValue" Height="40" Width="200" Grid.Column="1" Grid.Row="1" Margin="10"/>
</Grid>
with above code, i get the following window
private void btnAdd_Click(object sender, RoutedEventArgs e)
{
AddKeyValue(txtKey.Text, txtStringValue.Text);
}
private void AddKeyValue(object key, object value)
{
// load the resource dictionary
var rd = new System.Windows.ResourceDictionary();
rd.Source = new System.Uri("pack://application:,,,/LanguageResources;component/EnglishResources.xaml", System.UriKind.RelativeOrAbsolute);
// add the new key with value
rd.Add(key, value);
// now you can save the changed resource dictionary
var settings = new System.Xml.XmlWriterSettings();
settings.Indent = true;
var writer = System.Xml.XmlWriter.Create(#"EnglishResources.xaml", settings);
System.Windows.Markup.XamlWriter.Save(rd, writer);
}
If i click Add button the value should be inserted in the resource dictionary which(EnglishResources.xaml) is already i have. But it is not insert. Please help me out.
I need Like
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib">
<sys:String x:Key="add">ADD</sys:String>
<sys:String x:Key="key">Key</sys:String>
<sys:String x:Key="stringValue">String Value</sys:String>
<!-- the value should be inserted here. But not Insert-->
</ResourceDictionary>
After Added
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib">
<s:String x:Key="add">ADD</sys:String>
<s:String x:Key="key">Key</sys:String>
<s:String x:Key="stringValue">String Value</sys:String>
<!-- the value should be inserted here. But not Insert-->
</ResourceDictionary>
After i added the value into resource dictionary i get result like above. the sys is changed into to s and name space are merged as a line.
you can do it with this simple solution
private void AddKeyValue(object key, object value) {
// load the resource dictionary
var rd = new System.Windows.ResourceDictionary();
rd.Source = new System.Uri("pack://application:,,,/YOURAssemblyName;component/EnglishResources.xaml", System.UriKind.RelativeOrAbsolute);
// add the new key with value
//rd.Add(key, value);
if (rd.Contains(key)) {
rd[key] = value;
} else {
rd.Add(key, value);
}
// now you can save the changed resource dictionary
var settings = new System.Xml.XmlWriterSettings();
settings.Indent = true;
var writer = System.Xml.XmlWriter.Create(#"EnglishResources.xaml", settings);
System.Windows.Markup.XamlWriter.Save(rd, writer);
}
Usage
AddKeyValue("NewKey1", "StringValue");
AddKeyValue("NewKey2", 1000);
Hope that helps.