Silverlight: Add a resource dictionary from another project - silverlight

I have a XAML resource dictionary in project A. How can I merge it into a resource dictionary in project B?

Where Granite.Xaml is the library and ConvertersList.xaml has been marked as a resource.
<ResourceDictionary Source="/Granite.Xaml;component/ConvertersList.xaml" />
Here is the contents of the resource dictionary. Note that I had to include the assembly name in the namespace declaration even though the converters are in the same project as the dictionary. If you fail to do this you will get a runtime exception.
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converters="clr-namespace:Granite.Xaml.Converters;assembly=Granite.Xaml"
>
<converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
<converters:DebugBreakConverter x:Key="DebugBreakConverter" />
<converters:DebugTraceConverter x:Key="DebugTraceConverter" />
<converters:DictionaryConverter x:Key="DictionaryConverter" />
<converters:MaxLengthToBoolTrueConverter x:Key="MaxLengthToBoolTrueConverter" />
<converters:MinLengthToBoolTrueConverter x:Key="MinLengthToBoolTrueConverter" />
<converters:NotBoolToVisibilityConverter x:Key="NotBoolToVisibilityConverter" />
<converters:NotConverter x:Key="NotConverter" />
<converters:NotNullToBooleanConverter x:Key="NotNullToBooleanConverter" />
<converters:NotNullToVisibilityConverter x:Key="NotNullToVisibilityConverter" />
<converters:NotZeroToBooleanConverter x:Key="NotZeroToBooleanConverter" />
<converters:NotZeroToVisibilityConverter x:Key="NotZeroToVisibilityConverter" />
<converters:NullToBooleanConverter x:Key="NullToBooleanConverter" />
<converters:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />
<converters:StringToBooleanConverter x:Key="StringToBooleanConverter" />
<converters:StringToLowerConverter x:Key="StringToLowerConverter" />
<converters:StringToUpperConverter x:Key="StringToUpperConverter" />
<converters:ZeroToBooleanConverter x:Key="ZeroToBooleanConverter" />
<converters:ZeroToVisibilityConverter x:Key="ZeroToVisibilityConverter" />
</ResourceDictionary>

This works for me:
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Namespace.From.Your.Dll;component/Style.xaml"/>
</ResourceDictionary.MergedDictionaries>

Related

The type or namespace name 'Application' could not be found (are you missing a using d irective or an assembly reference?)

I'm trying to build a WPF aplication from command-line. And I'm using msbuild but build fails at compilation. I get this error.
I tried to add the reference assemblies but stil doesn't work. What do I have to do. I don´t want to use Visual Studio.
This is my code
using System;
using System.Collections.Generic;
using System.Windows;
namespace WpfTutorialSamples
{
public partial class App : Application
{
private void Application_Startup(object sender, StartupEventArgs e)
{
// Create the startup window
MainWindow wnd = new MainWindow();
// Do stuff here, e.g. to the window
wnd.Title = "Something else";
// Show the window
wnd.Show();
}
}
}
This is the xaml code
<Application x:Class="WpfTutorialSamples.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Startup="Application_Startup">
<Application.Resources></Application.Resources>
</Application>
And this is the msbuild code
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Compile Include="App.xaml.cs" />
</ItemGroup>
<Target Name="Build">
<Csc Sources="#(Compile)"/>
</Target>
</Project>
I've trying several sites and references to learn, perhaps everyone likes Visual Studio and I haven´t found a reference where I can develop with command-line.
Usually to compile project from command line I would suggest to use project file created by the Visual Studio. Try to add references for the framework libraries like below:
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
Additional information about using an MSBuild is here: Using MSBuild

How to mention source for BubbleSeries2D.Points

For a WPF project with Dev Express, is there a way i can define a series in the .xaml.cs file and reference this in the xaml file instead of manually writing the points as shown -
<Window x:Class="Bubble2DChart.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dxc="http://schemas.devexpress.com/winfx/2008/xaml/charts" Title="Window1" Height="350" Width="620">
<Grid>
<dxc:ChartControl>
<dxc:ChartControl.CrosshairOptions>
<dxc:CrosshairOptions ShowValueLine="True" ShowValueLabels="True"/>
</dxc:ChartControl.CrosshairOptions>
<dxc:ChartControl.Diagram>
<dxc:XYDiagram2D>
<dxc:XYDiagram2D.Series>
<dxc:BubbleSeries2D Transparency="0.2" AutoSize="False" MinSize="1" MaxSize="3" ColorEach="True"
CrosshairLabelPattern="Argument: {A}; Value: {V}; Weight: {W}">
<dxc:BubbleSeries2D.Points>
<dxc:SeriesPoint Argument="A" Value="100" dxc:BubbleSeries2D.Weight="0.9" />
<dxc:SeriesPoint Argument="B" Value="60" dxc:BubbleSeries2D.Weight="0.8" />
<dxc:SeriesPoint Argument="C" Value="30" dxc:BubbleSeries2D.Weight="0.5" />
<dxc:SeriesPoint Argument="D" Value="43" dxc:BubbleSeries2D.Weight="0.4" />
<dxc:SeriesPoint Argument="E" Value="11" dxc:BubbleSeries2D.Weight="0.4"/>
<dxc:SeriesPoint Argument="F" Value="29" dxc:BubbleSeries2D.Weight="0.2"/>
<dxc:SeriesPoint Argument="G" Value="12" dxc:BubbleSeries2D.Weight="0.2"/>
<dxc:SeriesPoint Argument="H" Value="21" dxc:BubbleSeries2D.Weight="0.2"/>
<dxc:SeriesPoint Argument="I" Value="28" dxc:BubbleSeries2D.Weight="0.2"/>
</dxc:BubbleSeries2D.Points>
</dxc:BubbleSeries2D>
</dxc:XYDiagram2D.Series>
<dxc:XYDiagram2D.AxisY>
<dxc:AxisY2D GridLinesMinorVisible="True" >
<dxc:AxisY2D.WholeRange>
<dxc:Range MinValue="0" MaxValue="130"
SideMarginsValue="0" />
</dxc:AxisY2D.WholeRange>
</dxc:AxisY2D>
</dxc:XYDiagram2D.AxisY>
</dxc:XYDiagram2D>
</dxc:ChartControl.Diagram>
</dxc:ChartControl>
</Grid>
I suggest you to go through documentation: Bind a Series to a Data Source
To do this, assign your data source to the Series.DataSource property, and define the Series.ArgumentDataMember and Series.ValueDataMember properties.
You can bind a Chart to an Observable Collection, Data from an MDB File, Static Resource etc. You can follow the example to implement your functionality.

WPF log4net is not writing to the log file [duplicate]

This question already has an answer here:
WPF-Log4Net used inside VSIX extension did not output log when installed at target VS
(1 answer)
Closed 4 years ago.
I have a WPF solution. I downloaded log4net dll, I added log4net.config and had set the "Copy to Output Directory" value as "Copy always".
log4net.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<log4net>
<root>
<level value="ALL" />
<appender-ref ref="LogFileAppender" />
</root>
<appender name="LogFileAppender" type="log4net.Appender.FileAppender">
<file value="myapp.txt" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="5" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %level %logger - %message%newline" />
</layout>
</appender>
</log4net>
</configuration>
And I added the below line in AssemblyInfo.cs:
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]
then the below code in my TestWindowControl.xaml.cs
public partial class TestWindowControl : UserControl
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public TestWindowControl()
{
XmlConfigurator.Configure(new System.IO.FileInfo("log4net.config"));
log.Info("info testing");
log.Debug("debug testing");
log.Error("error testing");
log.Fatal("fatal testing");
log.Warn("warn testing");
}
}
But logs are not writing to the file. It's working in Console application but not working for WPF. Am I missing something?
Try to set the filter inside appender
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="WARN" />
<levelMax value="ERROR" />
</filter>

How use Style in PageFunction?

How use Style in PageFunction?
This construction is not work:
<PageFunction.Resources>
<Style ... />
</PageFunction.Resources>

How to know when a XAML element is finished loading

I have a custom control I'm developing that has a collection of items. When adding an item to the collection you're meant to do:
myCustomControl.BeginAddItems();
myCustomControl.Items.Add("a");
myCustomControl.Items.Add("b");
myCustomControl.Items.Add("c");
myCustomControl.EndAddItems();
If defining in XAML it would be:
<MyControl>
<Items>
<Item Name="a" />
<Item Name="b" />
<Item Name="c" />
</Items>
</MyControl>
How can I have EndAddItems (and ideally BeginAddItems) called when loading from XAML? Is there any way that MyControl can be notified by XAML that it has finished loading?
You can use the Loaded event

Resources