|
You're welcome.
"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
|
|
|
|
|
Hi All,
I've just noticed something in the Juval Lowy book I'm reading at the mo. He hasn't actually mentioned this in the text but I've noticed that all his DataContract are structs not classes.
Kinda makes sense really, are you WCF'ers out there tending to do the same with your DCs?
Cheers,
|
|
|
|
|
Nope, and here are my reasons:
- If your contract isn't small, a struct doesn't make much sense. If we assume you have non-trivial data, then the stack usage more than outweighs the prevention of heap allocation that structs bring to the table.
- You cannot use default constructors or field initializers with structs, which we use a fair bit.
- Structs tend to make sense when they are used in lots of places. Assuming that they don't form a large part of your architecture, then you aren't going to see much benefit from them.
"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
|
|
|
|
|
Hi Pete,
I was just thinking about in terms of the internal server farm project I'm working on. I've designed a set of base data classes for our database team to use in relation to reading data from the DB and then shoving it down the pipe to a WCF service. They are small data classes.
Might need to do some testing around this to help weigh up the pros and cons.
Cheers,
|
|
|
|
|
I have a form that has several labels that are updated on a regular basis. I was under the assumption that if I set up a proper class (inheriting from INotifyPropertyChanged), events would be sent to the form whenever a property changed. So, I wrote this (abbreviated to avoid boring you):
public class FormProperties : INotifyPropertyChanged
{
private string m_scrambledWord;
public string ScrambledWord
{
get { return m_scrambledWord; }
set
{
m_scrambledWord = value;
OnPropertyChanged("ScrambledWord");
}
}
public FormProperties()
{
m_scrambledWord = "test";
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
And in the form, I'm doing this:
FormProperties m_formProperties = new FormProperties();
Finally, I'm doing this in the XAML:
<Window x:Class="AnagramsWPF.WindowMain"
x:Name="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:AnagramsWPF"
Title="Anagrams/WPF"
Height="566" Width="487"
FontFamily="Arial" FontSize="13"
DataContext="m_formProperties"> <----------------
<Grid>
<TextBox Name="textboxScrambled"
Height="23"
Width="126"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Margin="111,6,0,0"
IsReadOnly="True"
MaxLines="1"
MaxLength="10"
CharacterCasing="Upper"
Text="{Binding Path=ScrambledWord, Mode=OneWay}" />
</Grid>
</Window>
I was expecting the form to be initialized with the associated textbox being set to "test". What am I doing wrong?
BTW, this databinding stuff seems like it's the long way around to setting the controls on a form.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
John - your problem is in the constructor:
m_scrambledWord = "test";
As you are setting the member directly, the property isn't invoked - hence, the notification mechanism doesn't fire. Change this to:
ScrambledWord = "test";
"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
|
|
|
|
|
Still no workee. :/
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
You cannot bind to a field. You would have to expose it as a CLR property.
|
|
|
|
|
I really should read these posts more carefully. What you need to do is set your binding up explicitly, as in:
<Window x:Class="JsopBinding.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300" x:Name="myWindow"> <-- Set the name here - you need it below -->
<Window.DataContext>
<Binding ElementName="myWindow" Path="Properties" /> <-- Now, set up the data context binding -->
</Window.DataContext>
<Grid>
<TextBox
Name="textboxScrambled"
Height="23"
Width="126"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Margin="111,6,0,0"
IsReadOnly="True"
MaxLines="1"
MaxLength="10"
CharacterCasing="Upper"
Text="{Binding Path=ScrambledWord, Mode=OneWay}" />
</Grid>
</Window> And, in your code behind you add the property:
public FormProperties Properties
{
get { return m_formProperties; }
set { m_formProperties = value; }
} Alternatively, you can assign your datacontext directly in the code behind as
this.DataContext = m_formProperties;
"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
|
|
|
|
|
Yeah, that worked (setting up a property that gets/sets the ForumProperties).
Many thanks, oh great and powerful Oz.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
You are soooo welcome, now let's go and trample on some egos.
"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: now let's go and trample on some egos.
I do that at every opportunity. However, I believe in fair play, and therefore feel that I must wait for someone to actually step on their dick before I point and laugh.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
I prefer to be pre-emptive. When I passed 40, I realised that I enjoyed being a grumpy old sod, so I didn't have to worry about any touchy feely crap.
"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
|
|
|
|
|
I find that waiting for some idiot to provide me with a basis for my comments allows me to better organize my thoughts.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Hi ,
I need to develop a Custom List control in WPF in which i need to customize the list header,the list selection,list background and need to add images to the listitem. I have created like this one in MFC with ownerdraw but not aware of WPF. Can anyone let me know some articles helping me to develop one.
Thanks
|
|
|
|
|
Why do you need to create a custom list control? The whole point behind the controls in WPF is that they are "lookless". In other words, their behaviour is separated from the visuals, so you can restyle existing controls with relative ease.
Here's a (pretty completely) restyled version of a ListBox (thanks to KaXAML):
<Style x:Key="{x:Static GridView.GridViewScrollViewerStyleKey}" TargetType="{x:Type ScrollViewer}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ScrollViewer}">
<Grid Background="{TemplateBinding Background}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<DockPanel Margin="{TemplateBinding Padding}">
<ScrollViewer
DockPanel.Dock="Top"
Focusable="false"
HorizontalScrollBarVisibility="Hidden"
VerticalScrollBarVisibility="Hidden">
<GridViewHeaderRowPresenter
Margin="2,0,2,0"
AllowsColumnReorder="{Binding Path=TemplatedParent.View.AllowsColumnReorder,RelativeSource={RelativeSource TemplatedParent}}"
ColumnHeaderContainerStyle="{Binding Path=TemplatedParent.View.ColumnHeaderContainerStyle,RelativeSource={RelativeSource TemplatedParent}}"
ColumnHeaderContextMenu="{Binding Path=TemplatedParent.View.ColumnHeaderContextMenu,RelativeSource={RelativeSource TemplatedParent}}"
ColumnHeaderTemplate="{Binding Path=TemplatedParent.View.ColumnHeaderTemplate,RelativeSource={RelativeSource TemplatedParent}}"
ColumnHeaderTemplateSelector="{Binding Path=TemplatedParent.View.ColumnHeaderTemplateSelector,RelativeSource={RelativeSource TemplatedParent}}"
ColumnHeaderToolTip="{Binding Path=TemplatedParent.View.ColumnHeaderToolTip,RelativeSource={RelativeSource TemplatedParent}}"
Columns="{Binding Path=TemplatedParent.View.Columns,RelativeSource={RelativeSource TemplatedParent}}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</ScrollViewer>
<ScrollContentPresenter Name="PART_ScrollContentPresenter" KeyboardNavigation.DirectionalNavigation="Local"/>
</DockPanel>
<ScrollBar
Name="PART_HorizontalScrollBar"
Grid.Row="1"
Maximum="{TemplateBinding ScrollableWidth}"
Orientation="Horizontal"
Value="{TemplateBinding HorizontalOffset}"
ViewportSize="{TemplateBinding ViewportWidth}"
Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"/>
<ScrollBar
Name="PART_VerticalScrollBar"
Grid.Column="1"
Maximum="{TemplateBinding ScrollableHeight}"
Value="{TemplateBinding VerticalOffset}"
ViewportSize="{TemplateBinding ViewportHeight}"
Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="GridViewColumnHeaderGripper" TargetType="{x:Type Thumb}">
<Setter Property="Width" Value="18"/>
<Setter Property="Background" Value="#404040"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Thumb}">
<Border Background="Transparent" Padding="{TemplateBinding Padding}">
<Rectangle Width="1" HorizontalAlignment="Center" Fill="{TemplateBinding Background}"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="{x:Type GridViewColumnHeader}" TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
<Grid>
<Border
Name="HeaderBorder"
Background="#E0E0E0"
BorderBrush="#404040"
BorderThickness="0,1,0,1"
Padding="2,0,2,0">
<ContentPresenter
Name="HeaderContent"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
Margin="0,0,0,1"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
RecognizesAccessKey="True"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</Border>
<Thumb
x:Name="PART_HeaderGripper"
HorizontalAlignment="Right"
Margin="0,0,-9,0"
Style="{StaticResource GridViewColumnHeaderGripper}"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="HeaderBorder" Property="Background" Value="#C0C0C0"/>
</Trigger>
<Trigger Property="IsPressed" Value="true">
<Setter TargetName="HeaderBorder" Property="Background" Value="#E0E0E0"/>
<Setter TargetName="HeaderContent" Property="Margin" Value="1,1,0,0"/>
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="Role" Value="Floating">
<Setter Property="Opacity" Value="0.7"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
<Canvas Name="PART_FloatingHeaderCanvas">
<Rectangle Width="{TemplateBinding ActualWidth}" Height="{TemplateBinding ActualHeight}" Fill="#60000000"/>
</Canvas>
</ControlTemplate>
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="Role" Value="Padding">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
<Border
Name="HeaderBorder"
Background="#E0E0E0"
BorderBrush="#404040"
BorderThickness="0,1,0,1"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="{x:Type ListView}" TargetType="{x:Type ListView}">
<Setter Property="SnapsToDevicePixels" Value="true"/>
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListView}">
<Border
Name="Border"
Background="#FFFFFF"
BorderBrush="#888888"
BorderThickness="1">
<ScrollViewer Style="{DynamicResource {x:Static GridView.GridViewScrollViewerStyleKey}}">
<ItemsPresenter/>
</ScrollViewer>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsGrouping" Value="true">
<Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter TargetName="Border" Property="Background" Value="#AAAAAA"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="{x:Type ListViewItem}" TargetType="{x:Type ListViewItem}">
<Setter Property="SnapsToDevicePixels" Value="true"/>
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Border
Name="Border"
Background="Transparent"
Padding="2"
SnapsToDevicePixels="true">
<GridViewRowPresenter VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter TargetName="Border" Property="Background" Value="#DDDDDD"/>
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="#888888"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
"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
|
|
|
|
|
I have a WPF project containing a RichTextBox .
I want the text not to wrap. I can force this by setting the PageWidth for the contained FlowDocument to be a large number. However, I really want the PageWidth to adjust itself to the length of the longest line (paragraph), so that the horizontal scroll bar thumb will have an appropriate length.
I tried setting PageWidth to Auto , but this did not prevent wrapping.
Thanks for your suggestions!
tfhain
|
|
|
|
|
i am developing an wpf applition,
in which s seprate window is used for to show some extra details from main window..
if i click one button it will open up the extra window..
the thing here is if i click anyother place in the screen, i have to close that extra widnow????
can any one help me regarding this, thanks now itslef.
|
|
|
|
|
To close a window you can use the Close[^] method.
e.g.,
yourWindowObject.Close();
|
|
|
|
|
i am using an WPF application..
here the visual children count is comming as 0..
even i am having number of childrens there. how to get the visual childer?
|
|
|
|
|
If you're getting 0 as a visual children count, this means you're probably looking in the wrong place. Try to get the count AFTER youc call InitializeComponent in your window.
"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
|
|
|
|
|
yes mr hanlon..
i m calling this method at the end of my constructor, in which the first step of my constructor is that initialize component
|
|
|
|
|
You are doing it too soon. As a test, add a button to your form, add a click event handler and add the call to TraverseVisualTree to the click handler.
"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
|
|
|
|
|
i m using one wpf window.. in that i have some number of canvas,..
i have to do some functions dynamically for all the canvas..
for that i have to take all the canvas together in loop..
for that in windows we will use like
foreach(Canvas cv in this.controls)
cv.visiblity = hidden..
like this we wil do..
but in WPF
i m unable to take the this.controls..
how to take that one???
|
|
|
|
|
If you have the name of the Canvas elements then you can do a FindName[^] using the the window object
else you would have to use VisualTreeHelper[^] [^]
|
|
|
|