|
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[^] [^]
|
|
|
|
|
The controls are laid out using a Visual Tree, so you walk the tree to find children. To do this, you use the VisualTreeHelper class to get the children. Something like this will do it:
internal static void TraverseVisualTree(object current)
{
DependencyObject ob = current as DependencyObject;
int counter = VisualTreeHelper.GetChildrenCount(ob);
for (int i = 0; i < counter; i++)
{
object depObj = VisualTreeHelper.GetChild(ob, i);
TraverseVisualTree(depObj);
}
}
} All you do then is call:
TraverseVisualTree(this);
"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..
but u have given the object current as paramater...
that is it expects an object as parameter..
what is that object ?? what i have to send there
|
|
|
|
|
I already answered that, when I told you how to call it. You can use the this parameter in your Window/UserControl class.
"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
|
|
|
|
|
sorry..
i as it was seperated i dont read that one
|
|
|
|
|
Mr hanlon..
DependencyObject ob = current as DependencyObject;
int counter = VisualTreeHelper.GetChildrenCount(ob);
in this i m getting the counter as 0.. but i have more number childrens in the window
|
|
|
|
|
Hi i create my own Grid using ListView Control in WPF
There are couple of think in which i am facing problem.
1. In Column i use a Toggle button which is used to select the listViewItem. but when i press the Toggle button click event occur at that time how i can get the object of listViewItem. Note i use the GetFocus event for the ListViewItem but it fire at first time when i click the button. i just want that when button isChecked the the listViewItem Opacity should 1.0 and if not Checked then it should 0.4.
2. When i select any listView item the selection colour is Blue how can i chage that color.
WANTED wasim khan(Killed 50 Innocent Buggs, Distroyed 200 Exception, make 5 Project Hostage) any Compnay Hire him will pay 30,000. Best place where u can get him is Sorcim Technologies Murre Road RWP
|
|
|
|
|
|
hello this is my first animation practice in WPF
so I considered it a very big achievment !!
but I want to animate the item like carasoul panel (control of Infaragistics) :
- how can I animate the buttons that contain advertisement image and when the user
hover on button the all buttons stop not only the button
- how can I make the same animation for all buttons but not in the same time
this is my Powerfull user control code :
<UserControl x:Class="AdvertisementsPanel.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Loaded="UserControl_Loaded">
<UserControl.Resources>
<Style x:Key="AdvertisementItem" TargetType="{x:Type Button}">
<Setter Property="MaxHeight" Value="75" />
<Setter Property="MinHeight" Value="75" />
<Setter Property="MaxWidth" Value="110" />
<Setter Property="MinWidth" Value="110" />
<Setter Property="Opacity" Value=".5" />
<Style.Triggers>
<EventTrigger RoutedEvent="Mouse.MouseEnter">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Duration="0:0:0.2"
Storyboard.TargetProperty="MaxHeight"
To="90" />
<DoubleAnimation
Duration="0:0:0.2"
Storyboard.TargetProperty="MaxWidth"
To="140" />
<DoubleAnimation
Duration="0:0:0.2"
Storyboard.TargetProperty="Opacity"
To="1.0" />
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
<EventTrigger RoutedEvent="Mouse.MouseLeave">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Duration="0:0:1"
Storyboard.TargetProperty="MaxHeight" />
<DoubleAnimation
Duration="0:0:1"
Storyboard.TargetProperty="MaxWidth" />
<DoubleAnimation
Duration="0:0:0.2"
Storyboard.TargetProperty="Opacity" />
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
<EventTrigger RoutedEvent="Loaded" >
<BeginStoryboard Name="MyBeginStoryBoard" >
<Storyboard>
<DoubleAnimation
Storyboard.TargetProperty="(Canvas.Top)"
To="250" Duration="0:0:7" RepeatBehavior="Forever"
/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="MouseMove">
<PauseStoryboard BeginStoryboardName="MyBeginStoryBoard" />
</EventTrigger>
<EventTrigger RoutedEvent="MouseLeave">
<ResumeStoryboard BeginStoryboardName="MyBeginStoryBoard" />
</EventTrigger>
</Style.Triggers>
</Style>
</UserControl.Resources>
<Grid>
<Canvas ClipToBounds="True" Name="maincanvas" >
<Button Canvas.Left="10" Canvas.Top="10" Style="{StaticResource AdvertisementItem}" Height="110" Width="130" Name="button1" >Advertisement</Button>
</Canvas>
</Grid>
</UserControl>
thanks a lot
You have To Search About The Truth Of Your Life
Why Are you Here In Life ?
|
|
|
|
|
Feras Mazen Taleb wrote: how can I make the same animation for all buttons but not in the same time
I don't understand this statement.
Take a look at this list of crazy WPF layout panels.[^].
|
|
|
|
|
ABitSmart wrote: Take a look at this list of crazy WPF layout panels.
thanks for that
I will try to clear my idea
I need to make a vertical list of photos that animate from up to down this is my simple idea
in the previous xaml code you will notice that I put one button that animate from up to down repeatedly
I want to put many photos but each photo has its own start and end point
and when the photo reach the down I want to push it in the first (ie return it to the top)
I hope that i cleared my idea
You have To Search About The Truth Of Your Life
Why Are you Here In Life ?
|
|
|
|
|
I'm waiting my friend I just need the starting point
to know how to build this control
You have To Search About The Truth Of Your Life
Why Are you Here In Life ?
|
|
|
|
|
this is the last thing I Achieved :
I added the animation to the buttons programmatically
this is the code behind file :
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.Windows.Media.Animation;
namespace practiceOnAnimationClasses
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
DoubleAnimationUsingPath Animation1 = new DoubleAnimationUsingPath();
private void Window_Loaded(object sender, RoutedEventArgs e)
{
List<Button> buttons = new List<Button>(5);
buttons.Add(new Button() { Width = 120d, Height = 75d, Content = "Advertisement 1" });
buttons.Add(new Button() { Width = 120d, Height = 75d, Content = "Advertisement 2" });
buttons.Add(new Button() { Width = 120d, Height = 75d, Content = "Advertisement 3" });
buttons.Add(new Button() { Width = 120d, Height = 75d, Content = "Advertisement 4" });
buttons.Add(new Button() { Width = 120d, Height = 75d, Content = "Advertisement 5" });
int count = 0;
foreach (var item in buttons)
{
MainCanvas.Children.Add(item);
DoubleAnimation myDoubleAnimation = new DoubleAnimation();
myDoubleAnimation.From = 75 + (count * item.Width);
myDoubleAnimation.To = 800;
myDoubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(15));
myDoubleAnimation.AutoReverse = false;
myDoubleAnimation.RepeatBehavior = RepeatBehavior.Forever;
item.BeginAnimation(Canvas.LeftProperty, myDoubleAnimation);
count++;
}
}
}
}
Xaml File it only contains the mainCanvas that I will Add
Buttons to It
the movement is very creasy and wrong How Can I make the movement
like photo gallery
<Window x:Class="practiceOnAnimationClasses.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="563" Loaded="Window_Loaded">
<Window.Resources>
<!--<Storyboard x:Key="StoryboardPath">
<DoubleAnimationUsingPath BeginTime="00:00:00" Duration="00:00:02" Storyboard.TargetName="button" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" Source="X">
<DoubleAnimationUsingPath.PathGeometry>
<PathGeometry Figures="M-3,2 L363,2 L363,83 L-3,83 z"/>
</DoubleAnimationUsingPath.PathGeometry>
</DoubleAnimationUsingPath>
<DoubleAnimationUsingPath BeginTime="00:00:00" Duration="00:00:02" Storyboard.TargetName="button" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" Source="Y">
<DoubleAnimationUsingPath.PathGeometry>
<PathGeometry Figures="M-3,2 L363,2 L363,83 L-3,83 z"/>
</DoubleAnimationUsingPath.PathGeometry>
</DoubleAnimationUsingPath>
</Storyboard>-->
</Window.Resources>
<Canvas Name="MainCanvas"></Canvas>
</Window>
You have To Search About The Truth Of Your Life
Why Are you Here In Life ?
|
|
|
|