|
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
|
|
|
|
|
Mike - what error do you get? Apart from the invalid markup here horizontalalignment="Stretch">;Style="{StaticResource CustomBorderStyle}", this all looks perfectly legal (assuming, of course, that you have just made a mistake typing your markup in here because XAML is case sensitive, so textbox is not the same as TextBox).
"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
modified on Monday, March 16, 2009 4:52 AM
|
|
|
|
|
Thanks for your input Pete,
Pete O'Hanlon wrote: horizontalalignment="Stretch">;Style="{StaticResource CustomBorderStyle}"
I'm a terrible typer...I was going back and adding the < and > 's and produced the typo.
I get these error periodically when working with UserControls, which is where the style is used and I get 3 errors.
Could not create instance of ProjectView (my user control)
Value TaskMgrResourceDictionary.xaml cannot be assigned to property 'Source'. The resource dictionary XAML file has errors and cannot be loaded.
The application XAML file failed to load. Fix errors in the application XAML before opening the XAML files.
Like you if I strip this code out and and use it in line it works great. Its in several locations also, and all are user controls? Except for the MainWindow not showing because of the errors in the user controls.
Thanks,
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
|
|
|
|
|
Mike Hankey wrote: Value TaskMgrResourceDictionary.xaml cannot be assigned to property 'Source'. The resource dictionary XAML file has errors and cannot be loaded.
Since it works inline, your problem seems to be in the resources, as
indicated by the errors. That's probably a good place to look for errors
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark,
I had this problem using a DataGrid control and turned out that I could remove the code that styled the headers and it worked for a while then quit again a short time later. I'm thinking it has something to do with UserControls but not quite sure. The reason I posted this question was to see if anyone else had had this problem using UserControls in their app. I've heard that there are problems using them and was wanting to see if this was one of them.
Thanks,
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
|
|
|
|