|
I am new to the world of WPF - so not sure how to do the below functionality. It will be great if someone can help me.
I have developed an app using WPF (XAML). What I am trying to do is during the start up time of the app, I am trying to read a file (.txt and xml) and I am trying to load the content for the controls from there. Those names will overwrite the default names for the controls given in the xaml files. I am loading the default names in xaml file from a resx file.
For example, one control is the name of the. In resx file, I stored "default user". Now every user should be able to display there name by simple adding a pre-defined tag "My_Name" and then providing there name in a .txt file. The app, on strat up, should load that string from the .txt file.
I found out a way to do it in the code - by reading the string from the file and assiging thet Control.Content = "Name_Read_From_File" - but I am trying to do it at the strat-up time by parsing the xaml file directly - so that I can restrict the functionality in one place. Many thanks in advance...
|
|
|
|
|
Hey Is there anybody tried to create a chat room in WPF application. Mine is a client server application. i want to create a chat room.
Appreciate any kind of help....
|
|
|
|
|
Hi, I am using a WPF ListView bound to an observable collection to display records in the form of a Grid. How can I export this data in ListView to excel?
Pankaj Chamria,
Software Programmer.
|
|
|
|
|
Why do you think this has something to do with WPF?
Write a method that loops over your collection and write the data to the excel file. Here[^].
Eslam Afifi
|
|
|
|
|
The ListView in WPF is so different to the Forms one.
Maybe the problem is how to iterate inside the ListView items.
Here it is:
GridView grid = source.View as GridView;
if (grid == null)
{
return;
}
foreach (GridViewColumn col in grid.Columns)
{
}
foreach (Object item in source.Items)
{
PropertyInfo[] dataFields = item.GetType().GetProperties();
int i = 0;
foreach (GridViewColumn col in grid.Columns)
{
try
{
string strPath = ((Binding)col.DisplayMemberBinding).Path.Path;
object propValue = GetValue(item, source.Items, strPath);
}
catch (Exception)
{
}
}
}
I think it will be easier to export (to excel, pdf or anything) from here.
|
|
|
|
|
Any body help me
I want to create a button dynamically when click another button,
How can write this code, only a xaml file.
Thanks....
|
|
|
|
|
You want to write the code in XAML only?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
i want the concept of dynamic control creation and that control must
have the style.
Thanks...
|
|
|
|
|
Like this?
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="600" Width="300">
<Grid>
<Grid.Resources>
<Style TargetType="{x:Type Button}">
<Setter Property="Background" Value="Azure" />
</Style>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.Children>
<StackPanel x:Name="stack" />
<Button HorizontalAlignment="Center" Grid.Row="1" Content="Add button" Click="Button_Click" />
</Grid.Children>
</Grid>
</Window>
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace WpfApplication1
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
var button = new Button() { Content = "Newly added button" };
var rnd = new Random(DateTime.Now.ToBinary().GetHashCode());
switch (rnd.Next(3))
{
case 0:
button.Background = Brushes.BlueViolet;
break;
case 1:
var style = new Style();
style.Setters.Add(new Setter(Button.BackgroundProperty, Brushes.DarkBlue));
button.Style = style;
break;
}
stack.Children.Add(button);
}
}
}
Eslam Afifi
|
|
|
|
|
I discourage the use of this method unless you really "really" have to put your class in a single xaml file. I can't even think of a scenario where you'd have to use this method.
I've just found out that you can place both the markup and the code in the xaml file.
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="600" Width="300">
<Grid>
<Grid.Resources>
<Style TargetType="{x:Type Button}">
<Setter Property="Background" Value="Azure" />
</Style>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.Children>
<StackPanel x:Name="stack" />
<Button HorizontalAlignment="Center" Grid.Row="1" Content="Add button" Click="Button_Click" />
</Grid.Children>
</Grid>
<x:Code>
<![CDATA[
public Window1()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
var button = new Button() { Content = "Newly added button" };
var rnd = new Random(DateTime.Now.ToBinary().GetHashCode());
switch (rnd.Next(3))
{
case 0:
button.Background = Brushes.BlueViolet;
break;
case 1:
var style = new Style();
style.Setters.Add(new Setter(Button.BackgroundProperty, Brushes.DarkBlue));
button.Style = style;
break;
}
stack.Children.Add(button);
}
]]>
</x:Code>
</Window>
You don't have to place the code in a CDATA section. You even can do this.
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="600" Width="300">
<Grid>
<Grid.Resources>
<Style TargetType="{x:Type Button}">
<Setter Property="Background" Value="Azure" />
</Style>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.Children>
<StackPanel x:Name="stack" />
<x:Code>
public Window1()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
var button = new Button() { Content = "Newly added button" };
var rnd = new Random(DateTime.Now.ToBinary().GetHashCode());
switch (rnd.Next(3))
</x:Code>
<Button HorizontalAlignment="Center" Grid.Row="1" Content="Add button" Click="Button_Click" />
</Grid.Children>
</Grid>
<x:Code>
{
case 0:
button.Background = Brushes.BlueViolet;
break;
case 1:
var style = new Style();
style.Setters.Add(new Setter(Button.BackgroundProperty, Brushes.DarkBlue));
button.Style = style;
break;
}
stack.Children.Add(button);
}
</x:Code>
</Window>
Eslam Afifi
|
|
|
|
|
Thank you for Replay
That code is enough. what i am expecting.
And I have another one doubt. How can use wpf in MVP/MVC
design pattern.
Thanks...
|
|
|
|
|
|
|
|
I have to insert items to treeview . using data binding . i am new to WPF
Pls anyone help me
my code is
<treeview itemssource="{Binding CategoryRecordList}" name="CategoryList<br mode=" hold=" /><br mode=">
|
|
|
|
|
|
|
Hi
I have two xaml file in my project Page.xaml and page2.xaml.
I want when user click on button from page.xaml then new popup window will be open for page2.xml. I have searched some examples but they open it in a same window.
Please Help
Thanks in advance
|
|
|
|
|
You have to open the second window in a dialog, see here[^] for details.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys
|
|
|
|
|
Thanks for the reply
But still the second window is opened in the same page.
Is there any way to open it in a other window?
|
|
|
|
|
There's no "other window"s in Silverlight.
Windows are controlled by the browser, so if you want a new window you
could use something like HtmlPage.PopupWindow[^] or HtmlWindow.Navigate[^]
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
The popups that you can create are on the same page (like AJAX Modal Dialogs).
You can open a popup calling from Silverlight a javascript function, but they will be an HTML popup (altough you can initialize inside another XAP application).
HTH
Braulio
/// -------------------------
Braulio Díez
DBSchemaEditor.com
Free Silverlight based DB Schema Modeling Tool
/// -------------------------
|
|
|
|
|
Hey y'all has anyone else run across this problem? and if so is there a work around?
I have a ResourceDictioinary where I have a linear brush declared;
<LinearGradientBrush x:Key="BlueLinearBrush" EndPoint="0.5,1" StartPoint="0.5,0">
<gradientstop color="PowderBlue" offset="0" />
<gradientstop color="SteelBlue" offset="1" />
</LinearGradientBrush>
and a style that uses the Brush
<style x:key="CustomBorderStyle" targettype="{x:Type Border}">
<setter property="Background" value="{StaticResource BlueLinearBrush}" />
.....
</style>
In my App.xaml file I have cone the MergeDictioinaires
then in my code I use it:
.....
<border horizontalalignment="Stretch">Style="{StaticResource CustomBorderStyle}">
<textblock text="{Binding Path=Name}" horizontalalignment="Center" fontweight="Bold" />
</border>
.....
but it gives me problems here?
I've googled and the examples I've found say this is legal as seen here[^]. The app runs fine but its annoying because I can't see the design or look at properties because of the error.
WTF?
Mike
"It doesn't matter how big a ranch ya' own, or how many cows ya' brand, the size of your funeral is still gonna depend on the weather." -Harry Truman.
Semper Fi
http://www.hq4thmarinescomm.com[ ^]
My Site
modified on Sunday, March 15, 2009 8:26 PM
|
|
|
|
|
Mike Hankey wrote: WTF?
No. That's "WPF"
I plugged your brush and style code in without using merged dictionaries (just put
it in the Application.Resources). Aside from the typo:
<border horizontalalignment="Stretch"> Style="{StaticResource CustomBorderStyle}">
which should be:
<border horizontalalignment="Stretch" Style="{StaticResource CustomBorderStyle}">
it worked fine.
What's the error?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks for your input Mark. See the response I gave to Pete.
Mike
"It doesn't matter how big a ranch ya' own, or how many cows ya' brand, the size of your funeral is still gonna depend on the weather." -Harry Truman.
Semper Fi
http://www.hq4thmarinescomm.com[ ^]
My Site
|
|
|
|