WPF Documents contains types that support FixedDocument, FlowDocument and XPS document creation.
Search This Blog
Monday, January 12, 2015
WPF Documents Namespace
WPF > Windows > Documents
WPF Documents contains types that support FixedDocument, FlowDocument and XPS document creation.
WPF Documents contains types that support FixedDocument, FlowDocument and XPS document creation.
Labels:
Documents
Thursday, November 13, 2014
Menu WPF Example
WPF > Controls > Menu
Menu presents a list of items that specify commands or options for an application. Typically, clicking an item on a menu opens a submenu or causes an application execute a command.
Example
Menu presents a list of items that specify commands or options for an application. Typically, clicking an item on a menu opens a submenu or causes an application execute a command.
Example
<Window x:Class="MapDecision.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<DockPanel>
<Menu DockPanel.Dock="Top">
<MenuItem Header="_File">
<MenuItem Header="_New"/>
<MenuItem Header="_Open"/>
<MenuItem Header="_Close"/>
<MenuItem Header="_Save"/>
</MenuItem>
</Menu>
<StackPanel></StackPanel>
</DockPanel>
</Window>
Labels:
Controls
Thursday, June 12, 2014
MultiBinding WPF Example
WPF > Windows > Data > MultiBinding
Represents a collection of Binding objects attached to a single binding target property.
Example
XAML
C#
Represents a collection of Binding objects attached to a single binding target property.
XAML
<Window x:Class="WpfApplication4.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"
xmlns:local="clr-namespace:WpfApplication4">
<Window.Resources>
<local:NameConvertor x:Key="nameConvertor"></local:NameConvertor>
</Window.Resources>
<Grid>
<Grid>
<TextBlock HorizontalAlignment="Left" Margin="20,30,0,0" TextWrapping="Wrap" Text="First Name"
VerticalAlignment="Top"/>
<TextBox x:Name="txtFirstName"
HorizontalAlignment="Left" Height="23" Margin="86,27,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
<TextBlock HorizontalAlignment="Left" Margin="20,68,0,0"
TextWrapping="Wrap" Text="Last Name" VerticalAlignment="Top"/>
<TextBox x:Name="txtLastName"
HorizontalAlignment="Left" Height="23" Margin="86,65,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
<TextBlock HorizontalAlignment="Left" Margin="20,110,0,0"
TextWrapping="Wrap" Text="Full Name" VerticalAlignment="Top"/>
<TextBox x:Name="txtLastName_Copy" HorizontalAlignment="Left" Height="23" Margin="86,107,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="267">
<TextBox.Text>
<MultiBinding Converter="{StaticResource
nameConvertor}" UpdateSourceTrigger="PropertyChanged">
<Binding ElementName="txtFirstName" Path="Text" />
<Binding ElementName="txtLastName" Path="Text" />
</MultiBinding>
</TextBox.Text>
</TextBox>
</Grid>
</Grid>
</Window>
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApplication4
{
public class NameConvertor : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return String.Concat(values[0], ",", values[1]);
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
{
return (value as string).Split(',');
}
}
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
}
Labels:
Data
Data Namespace WPF
Labels:
Data
Tuesday, June 3, 2014
ComboBoxItem WPF Example
WPF > Controls > ContentControl > ComboBoxItem
ComboBoxItem represent an item in a ComboBox.
Example:
XAML
ComboBoxItem represent an item in a ComboBox.
Example:
XAML
<Window x:Class="WpfApplication3.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<ComboBox x:Name="cbo"
HorizontalAlignment="Left" VerticalAlignment="Top" Width="120" SelectionChanged="ComboBox_SelectionChanged">
<ComboBoxItem>Option1</ComboBoxItem>
<ComboBoxItem>Option2</ComboBoxItem>
</ComboBox>
</Grid>
</Window>
C#
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
string value = ((ComboBoxItem)cbo.SelectedItem).Content.ToString();
}
Labels:
ContentControl
WPF Read RSS feed and bind to DataGrid
WPF > SyndicationFeed > Read RSS feed
Read RSS feed and bind to DataGrid
XAML
Read RSS feed and bind to DataGrid
XAML
<Window x:Class="Feed.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Rss
Feed" Height="670" Width="737" Loaded="Window_Loaded">
<Grid>
<DataGrid ItemsSource="{Binding RssFeedList}" AutoGenerateColumns="False"
IsReadOnly="True">
<DataGrid.Columns>
<DataGridTextColumn Header="Title" Binding="{Binding Title}"/>
</DataGrid.Columns>
</DataGrid>
</Grid>
</Window>
c#
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Feed
{
public class RssFeed
{
public string Title { get; set; }
}
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public ObservableCollection<RssFeed> RssFeedList { get; set; }
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
string feedUrl = "http://rss.cnn.com/rss/cnn_latest.rss";
System.Xml.XmlReader reader =
System.Xml.XmlReader.Create(feedUrl);
System.ServiceModel.Syndication.SyndicationFeed feed =
System.ServiceModel.Syndication.SyndicationFeed.Load(reader);
RssFeedList = new ObservableCollection<RssFeed>();
foreach (var item in feed.Items)
{
RssFeed rf = new RssFeed();
rf.Title =
item.Title.Text.ToString();
RssFeedList.Add(rf);
}
this.DataContext = this;
}
}
}
Labels:
SyndicationFeed
Wednesday, May 21, 2014
Get tree visual elements WPF
VisualTreeHelper provides methods that perform
tasks involving nodes in a visual tree.
Example:
Get tree visual elements for user control
FrameworkElement fe = (FrameworkElement)YourControl;
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(fe); i++)
{
Grid childVisual = (Grid)VisualTreeHelper.GetChild(fe, i);
childVisual.Width = sp.ActualWidth;
}
Labels:
WPF
Subscribe to:
Posts (Atom)