|
I edidted the post again,..the error raised from the underlined statement..
|
|
|
|
|
Basically, you have a frozen object here (you can tell this by checking mt.Matrix.IsFrozen). Once an object is frozen, you can't modify it - instead, you have to clone it and work with that.
"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 | Onyx
|
|
|
|
|
Pete O'Hanlon wrote: (you can tell this by checking mt.Matrix.IsFrozen).
i cannot find any handle like that, but i found something mt.Matrix.IsIdentity which is returns a bool value. What it does?..
Your corperation is really appreciated!
|
|
|
|
|
ASysSolvers wrote: i cannot find any handle like that, but i found something mt.Matrix.IsIdentity which is returns a bool value. What it does?..
This property identifies whether or not a matrix is the identity matrix. Basically, an identity matrix is a square matrix which has 1s on the main diagonal and 0s elsewhere.
"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 | Onyx
|
|
|
|
|
Do you have any idea to modify my code in the correct way?.. im struggled now.. i dont knw,.. i want to use this in WPF(Windows) application,..but fine in web it works,..
In windows it gives runtine error like in Thread subject..
|
|
|
|
|
Hello,
Currently im hanging on one Problem. I wrote a class inherting from grid. Each grid has the property
children. How can i get an notification when a new children added to the grid. I need somethink like a
event which occours when the children-cout changed. I hope you understand what i mean.
Thanks in advanced
|
|
|
|
|
You're looking at the ObservableCollection - that notifies you when an item has been added or removed from a collection.
"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 | Onyx
|
|
|
|
|
The Children property of a Grid is a UIElementCollection, which is not Observable, and is sealed.
So I have the same question - is there any way to see if the Children collection in a Panel has changed?
|
|
|
|
|
I am using wpf toolkit:Datagrid in my application with one Check box column and another textbox column. By default textbox column is Readonly.If Check box is checked then editing the textbox for particular row.
How can achieve the above scenario?...Thanks in advance
|
|
|
|
|
Does anyone know where to find the complete default control template xaml listings for the WPF controls?
Thanks.
Bob
|
|
|
|
|
The WPF documentation doesn’t list the XAML for standard control templates. But, you can write program to get the control template and then modify it and Re-Apply it.
Here is the program to get the control Template Markup of a given control.
In a Main window take a listbox control to enlist all the controls, and when any item is selected the corrosponding Control Template's Markup is displayed in a Textblock control.
Here is the WPF program to demonstrate the same
This is the XAML part
<Window x:Class="DefaultControlTemplate.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="462" Width="572" Loaded="Window_Loaded" >
<Grid>
<ListBox Margin="12,12,0,12" Name="listBox1" HorizontalAlignment="Left" Width="168" SelectionChanged="listBox1_SelectionChanged" />
<TextBlock HorizontalAlignment="Right" Margin="0,14,12,10" Name="textBlock1" Width="159" />
</Grid>
</Window>
This is how .cs file would look like
private void Window_Loaded(object sender, RoutedEventArgs e)
{
Type controlType = typeof(Control);
List<Type> ctrlTypes = new List<Type>();
//searches all the types in a dll where generic control class is defined
Assembly assembly = Assembly.GetAssembly(typeof(Control));
foreach (Type type in assembly.GetTypes())
{
// Only add a type of the list if it's a Control, a concrete class,
// and public.
if (type.IsSubclassOf(controlType) && !type.IsAbstract && type.IsPublic)
{
ctrlTypes.Add(type);
}
}
listBox1.ItemsSource = ctrlTypes;
}
------------------------------------------------------------
private void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
try
{
// Get the selected type.
Type type = (Type)listBox1.SelectedItem;
// Instantiate the type.
ConstructorInfo info = type.GetConstructor(System.Type.EmptyTypes);
Control control = (Control)info.Invoke(null);
// Get the template.
ControlTemplate template = control.Template;
// Get the XAML for the template.
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
StringBuilder sb = new StringBuilder();
XmlWriter writer = XmlWriter.Create(sb, settings);
XamlWriter.Save(template, writer);
textBlock1.Text = sb.ToString();
}
catch (Exception err)
{
textBlock1.Text = "<< Error generating template: " + err.Message + ">>";
}
}
---------------------------------------------------------
Let me explain the code:
At the Window_loaded event, I have enlisted all the controls in a list box.
When any of the items from list box is selected, I have created the control as per selection, got it's control template and serialized into XML and displayed the same in textblock as text.
If you want, you can start with a simpler program, say a window has a button and a textblock. When clicked on button,
the corrosponding XAML for button's control template will be displayed in textblock. In this case, Button is instantiated, hence need to created Button Object, as shown below.
private void button1_Click(object sender, RoutedEventArgs e)
{
ControlTemplate template = ((Control)sender).Template;
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
StringBuilder sb = new StringBuilder();
XmlWriter writer = XmlWriter.Create(sb, settings);
XamlWriter.Save(template, writer);
label1.Content = sb.ToString();
}
|
|
|
|
|
I ran your first version which looks promising, only the line:
ControlTemplate template = control.Template;
Always assigns a null value to the template variable.
The error message is typically:
<< Error generating template: Parameter name: obj>>
Are you seeing the same thing?
Thanks for your reply,
Bob
|
|
|
|
|
The error is obviously thrown by the line:
XamlWriter.Save(template, writer);
since template is null.
|
|
|
|
|
It appears that when you construct a WPF control in code, its Template property isn't initialized. For example:
ListBox listBox = new ListBox();
If you instantiate a ListBox like this, then walk the object hierarchy down to the Template property of the Control base class, you'll see that it hasn't been initilaized.
|
|
|
|
|
Turns out, after a little more exploration, that the Template property will be null unless the control has been rendered on the screen.
|
|
|
|
|
I know it sounds stupid but i'm looking for a way to style a textbox so that when it has focus it selects all the text. I know I could just call 'textBox.SelectAll()' (but i like to avoid x:Name). I could subclass the textbox and override OnFocus and call "SelectAll()" (but i don't like the idea). I'd really like to be able to do this in xaml by creating a style. I did a google check but came up empty
EDIT:
i just came across this solution[^]. I'm really hoping for a pure xaml solution but this will work.
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
|
|
Hi,
I tried to bind the list view with combo box, following code worked fine with Window1.xaml the same was not working in Page1.xaml. Any one pls help to solve the above. Thanks in advance.
My Xaml Code is:
<Page x:Class="WPFtest.ComboTest"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WPFtest"
Title="ComboTest">
<Page.Resources>
<local:BoolToVisibilityConverter x:Key="boolToVis" />
<Style TargetType="{x:Type TextBlock}"
x:Key="GridBlockStyle">
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Visibility"
Value="{Binding Path=IsSelected,
RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type ListViewItem}},
Converter={StaticResource boolToVis},
ConverterParameter=False}" />
</Style>
<Style TargetType="{x:Type FrameworkElement}"
x:Key="GridEditStyle">
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Visibility"
Value="{Binding Path=IsSelected,
RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type ListViewItem}},
Converter={StaticResource boolToVis},
ConverterParameter=True}" />
</Style>
</Page.Resources>
<StackPanel>
<TextBox Height="23" Name="textBox1" Width="120" />
<Button Height="23" Name="btnTest" Content="test" Width="120" Click="btnTest_Click"></Button>
<ListView x:Name="gameListView" ItemsSource="{Binding Path=GameCollection}">
<ListView.View>
<GridView>
<GridViewColumn Width="140">
<GridViewColumnHeader Click="SortClick"
Tag="GameName"
Content="Game Name" />
<GridViewColumn.CellTemplate>
<DataTemplate>
<Grid>
<TextBlock Text="{Binding Path=GameName}" Style="{StaticResource GridBlockStyle}"/>
<TextBox Text="{Binding Path=GameName}" Style="{StaticResource GridEditStyle}" />
</Grid>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="140">
<GridViewColumnHeader Click="SortClick" Tag="Creator" Content="Creator" />
<GridViewColumn.CellTemplate>
<DataTemplate>
<Grid>
<TextBlock Text="{Binding Path=Creator}" Style="{StaticResource GridBlockStyle}"/>
<ComboBox Name="cmbTest1" SelectedItem="{Binding Path=RoleID}" DisplayMemberPath="RoleName" SelectedValuePath="RoleID" ItemsSource="{Binding ElementName=This,Path=AvailableRoles}" Style="{StaticResource GridEditStyle}" />
</Grid>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="140">
<GridViewColumnHeader Click="SortClick"
Tag="Publisher"
Content="Publisher" />
<GridViewColumn.CellTemplate>
<DataTemplate>
<Grid HorizontalAlignment="Stretch">
<TextBlock Text="{Binding Path=Publisher}" Style="{StaticResource GridBlockStyle}"/>
<ComboBox Name="cmbTest" SelectedItem="{Binding Path=DeptID}" DisplayMemberPath="DeptName" SelectedValuePath="DeptID" ItemsSource="{Binding ElementName=This,Path=AvailablePublishers}" Style="{StaticResource GridEditStyle}" SelectionChanged="ComboBox_SelectionChanged" />
</Grid>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
<Button HorizontalAlignment="Right" Margin="5" Content="Add Row" Click="AddRowClick" />
</StackPanel>
</Page>
|
|
|
|
|
What does not work?
modified 27-Feb-21 21:01pm.
|
|
|
|
|
 Hi Karl,
Page loading with empty listview items from the ObservableCollections.I hv posted my code behind for your reference.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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;
using System.Collections.ObjectModel;
using System.ComponentModel;
namespace WPFtest
{
public partial class ComboTest : Page
{
private ObservableCollection<GameData> _GameCollection = new ObservableCollection<GameData>();
private ObservableCollection<Department> _AvailablePublishers = new ObservableCollection<Department>();
private ObservableCollection<Role> _AvailableRoles = new ObservableCollection<Role>();
private GridViewColumnHeader _CurSortCol = null;
private SortAdorner _CurAdorner = null;
public ComboTest()
{
_GameCollection.Add(new GameData {
GameName = "World Of Warcraft",
Creator = "Blizzard",
Publisher = "Blizzard" });
_GameCollection.Add(new GameData {
GameName = "Halo",
Creator = "Bungie",
Publisher = "Microsoft" });
_GameCollection.Add(new GameData {
GameName = "Gears Of War",
Creator = "Epic",
Publisher = "Microsoft" });
_AvailablePublishers.Add(new Department { DeptID = "1", DeptName = "Purchase" });
_AvailablePublishers.Add(new Department { DeptID = "2", DeptName = "production" });
_AvailablePublishers.Add(new Department { DeptID = "3", DeptName = "Inventory" });
InitializeComponent();
}
public ObservableCollection<GameData> GameCollection
{ get { return _GameCollection; } }
public ObservableCollection<Department> AvailablePublishers
{ get { return _AvailablePublishers; } }
public ObservableCollection<Role> AvailableRoles
{ get { return _AvailableRoles ; } }
private void AddRowClick(object sender, RoutedEventArgs e)
{
MessageBox.Show("Hi");
_GameCollection.Add(new GameData {
GameName = "A New Game",
Creator = "A New Creator",
Publisher = "<Select A Publisher>" });
}
private void SortClick(object sender, RoutedEventArgs e)
{
GridViewColumnHeader column =
sender as GridViewColumnHeader;
String field = column.Tag as String;
if (_CurSortCol != null)
{
AdornerLayer.GetAdornerLayer(
_CurSortCol).Remove(_CurAdorner);
gameListView.Items.SortDescriptions.Clear();
}
ListSortDirection newDir = ListSortDirection.Ascending;
if (_CurSortCol == column &&
_CurAdorner.Direction == newDir)
newDir = ListSortDirection.Descending;
_CurSortCol = column;
_CurAdorner = new SortAdorner(_CurSortCol, newDir);
AdornerLayer.GetAdornerLayer(
_CurSortCol).Add(_CurAdorner);
gameListView.Items.SortDescriptions.Add(
new SortDescription(field, newDir));
}
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ComboBox cmbTest = sender as ComboBox;
textBox1.Text = cmbTest.SelectedValue.ToString();
_AvailableRoles.Add(new Role { RoleID = "1", RoleName = "Executive" });
_AvailableRoles.Add(new Role { RoleID = "2", RoleName = "Manager" });
}
private void btnTest_Click(object sender, RoutedEventArgs e)
{
_GameCollection.RemoveAt(1);
}
}
public class Role : DependencyObject
{
public static readonly DependencyProperty role =
DependencyProperty.Register("roleId", typeof(string),
typeof(Role), new UIPropertyMetadata(null));
public string RoleID
{
get { return (string)GetValue(role); }
set { SetValue(role, value); }
}
public static readonly DependencyProperty roleNm =
DependencyProperty.Register("rolenm", typeof(string),
typeof(Role), new UIPropertyMetadata(null));
public string RoleName
{
get { return (string)GetValue(roleNm); }
set { SetValue(roleNm, value); }
}
}
public class Department : DependencyObject
{
public static readonly DependencyProperty DepartId =
DependencyProperty.Register("departmentId", typeof(string),
typeof(Department), new UIPropertyMetadata(null));
public string DeptID
{
get { return (string)GetValue(DepartId); }
set { SetValue(DepartId, value); }
}
public static readonly DependencyProperty DeptNam =
DependencyProperty.Register("deptName", typeof(string),
typeof(Department), new UIPropertyMetadata(null));
public string DeptName
{
get { return (string)GetValue(DeptNam); }
set { SetValue(DeptNam, value); }
}
}
public class GameData : DependencyObject
{
public static readonly DependencyProperty GameNameProperty =
DependencyProperty.Register("GameName", typeof(string),
typeof(GameData), new UIPropertyMetadata(null));
public string GameName
{
get { return (string)GetValue(GameNameProperty); }
set { SetValue(GameNameProperty, value); }
}
public static readonly DependencyProperty CreatorProperty =
DependencyProperty.Register("Creator", typeof(string),
typeof(GameData), new UIPropertyMetadata(null));
public string Creator
{
get { return (string)GetValue(CreatorProperty); }
set { SetValue(CreatorProperty, value); }
}
public static readonly DependencyProperty PublisherProperty =
DependencyProperty.Register("Publisher", typeof(string),
typeof(GameData), new UIPropertyMetadata(null));
public string Publisher
{
get { return (string)GetValue(PublisherProperty); }
set { SetValue(PublisherProperty, value); }
}
}
public class SortAdorner : Adorner
{
private readonly static Geometry _AscGeometry =
Geometry.Parse("M 0,5 L 10,5 L 5,0 Z");
private readonly static Geometry _DescGeometry =
Geometry.Parse("M 0,0 L 10,0 L 5,5 Z");
public ListSortDirection Direction { get; private set; }
public SortAdorner(UIElement element,
ListSortDirection dir)
: base(element)
{ Direction = dir; }
protected override void OnRender(
DrawingContext drawingContext)
{
base.OnRender(drawingContext);
if (AdornedElement.RenderSize.Width < 20)
return;
drawingContext.PushTransform(
new TranslateTransform(
AdornedElement.RenderSize.Width - 15,
(AdornedElement.RenderSize.Height - 5) / 2));
drawingContext.DrawGeometry(Brushes.Black, null,
Direction == ListSortDirection.Ascending ?
_AscGeometry : _DescGeometry);
drawingContext.Pop();
}
}
public class BoolToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType,
object parameter, System.Globalization.CultureInfo culture)
{
bool param = bool.Parse(parameter as string);
bool val = (bool)value;
return val == param ?
Visibility.Visible : Visibility.Hidden;
}
public object ConvertBack(object value, Type targetType,
object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
|
|
|
|
|
I don't see where you have assigned the DataContext.
You must set the ComboTest DataContext to the ComboTest class.
In you Loaded event add this line of code:
this.DataContext = this;
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Hi Karl,
Thanks...now listview loaded with data. I have one more issue, combo box not loaded.pls give me some suggestions. Thanks inadvance
|
|
|
|
|
The ItemsSource is incorrect.
ItemsSource="{Binding ElementName=This
Change to ItemsSource={Binding Path=...}
... is the property name that holds the collection.
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Hi,
till combo is not loaded,
<ComboBox Name="cmbTest" SelectedItem="{Binding Path=DeptID}" DisplayMemberPath="DeptName" SelectedValuePath="DeptID" ItemsSource="{Binding ElementName=This,Path=AvailablePublishers}" Style="{StaticResource GridEditStyle}" SelectionChanged="ComboBox_SelectionChanged" />
|
|
|
|
|