|
|
While creating style for a button I am writing like this:
<Style x:Key="MagButtonStyle" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid>
<Image Name="Normal" Source="Resources/Images/n0.png"/>
<Image Name="RollOver1" Source="Resources/Images/r1.png" Visibility="Hidden"/>
<Image Name="RollOver2" Source="Resources/Images/r2.png" Visibility="Hidden"/>
<Image Name="RollOver3" Source="Resources/Images/r3.png" Visibility="Hidden"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Normal" Property="Visibility" Value="Hidden"/>
<Setter TargetName="RollOver1" Property="Visibility" Value="Visible"/>
</Trigger>
</Style>
Can we control this trigger by some global variable/ dependency property defined in c# code? So, we would be able to use it with Multi-trigger?
Basically my requirement is to display different images based on property "DepProp". I need to be able to wrtite something like this:
<Trigger Property="DepProp" Value="1">
<Setter TargetName="RollOver1" Property="Visibility" Value="Visible"/>
</Trigger>
<Trigger Property="DepProp" Value="2">
<Setter TargetName="RollOver2" Property="Visibility" Value="Visible"/>
</Trigger>
Is it possible?
Other way around would be to access these style objects on mouseenter in c# code. Possible? If yes, how?
Which way will be better?
|
|
|
|
|
I have the same problem:
I need to put lines with different colors in a datagrid base on what happens in code behind.
I think one solution will be to attach a style with a trigger from the code behind.
Of course I wait to see how can access a code declared dependency property from xaml.
Maybe with a DataTrigger.
modified 15-Mar-12 13:10pm.
|
|
|
|
|
I wouldn't approach it like this. A simpler way to do this would be to implement a value converter which did the heavy work of just displaying the appropriate image, rather than showing and hiding elements.
|
|
|
|
|
Thanks! Yes your approach is better one. I opted for INotifyPropertyChanged and sorted out my issue.
|
|
|
|
|
I have solved my problem like here:
http://msdn.microsoft.com/en-us/library/system.windows.datatrigger.aspx
http://msdn.microsoft.com/en-us/library/ms668604.aspx
and I can put different colors in my grid based on the normal property from the Item class.
|
|
|
|
|
Thanks for sharing those links. Meanwhile I sorted out my requirement using 'INotifyPropertyChanged'.
|
|
|
|
|
I'm reading this[^].
If you scroll down a bit you will see this:
<Canvas>
<Canvas.Resources>
<ControlTemplate x:Key="DesignerItemTemplate" TargetType="ContentControl">
<ContentPresenter Content="{TemplateBinding ContentControl.Content}"/>
</ControlTemplate>
</Canvas.Resources>
<ContentControl Name="DesignerItem"
Width="100"
Height="100"
Canvas.Top="100"
Canvas.Left="100"
Template="{StaticResource DesignerItemTemplate}">
<Ellipse Fill="Blue"/>
</ContentControl>
</Canvas>
What does this do?
<Canvas.Resources>
<ControlTemplate x:Key="DesignerItemTemplate" TargetType="ContentControl">
<ContentPresenter Content="{TemplateBinding ContentControl.Content}"/>
</ControlTemplate>
</Canvas.Resources>
It looks like its biding the ContentPresenter to the controls content. Isn't that the default behavior anyway?
Everything makes sense in someone's mind
|
|
|
|
|
Kevin Marois wrote:
It looks like its biding the ContentPresenter to the controls content. Isn't that the default behavior anyway
Yes it is. How was this code generated?
If Expression Blend was used, this may have been generated automatically.
|
|
|
|
|
With a limited Grid space, I want to have a list of TextBoxes (email addresses). If the TextBoxes fill up the Grid space I want a vertical scroll bar to appear, so that the TextBoxes don't run into the next Grid space. If the scroll bar is there (but grayed out) because the TextBoxes do not fill up the Grid space, that's OK.
I'm using WPF and C#.
Thanks.
|
|
|
|
|
Just put a ListBox inside your Grid . Change the ItemTemplate so that it displays a TextBox instead of a TextBlock .
|
|
|
|
|
Thanks. I can only define the ListBox in the WPF section. My TextBlocks and TextBoxes have to done on the fly in the C# section, depending on user data. Something like:
Email #1 <<email1 textbox="">>
Email #2 <<email3 textbox="">>
Email #3 <<email3 textbox="">>
.
.
.
|
|
|
|
|
I think you're misunderstanding me here. Imagine you have the following
public class EmailItem : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private string emailAddress;
private int emailCount;
public string EmailAddress
{
get { return emailAddress; }
set
{
if (emailAddress == value) return;
emailAddress = value;
NotifyPropertyChanged("EmailAddress");
}
}
public int EmailCount
{
get { return emailCount; }
set
{
if (emailCount== value) return;
emailCount = value;
NotifyPropertyChanged("EmailCount");
}
}
private void NotifyPropertyChanged(string property)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler == null) return;
handler(this, new PropertyChangedEventArgs(property));
}
}
public class Emails
{
public Emails()
{
EmailList = new ObservableCollection<EmailList>();
}
public ObservableCollection<EmailList> EmailList { get; set; }
} Now, in your XAML, you bind your ListBox to the EmailList collection via the ItemSource . Finally, you set up an ItemTemplate for the ListBox .
<DataTemplate x:Key="emailsTemplate">
<Grid>
<Grid.ColumnDefinition>
<ColumnDefinition Width="180" />
<ColumnDefinition />
</Grid.ColumnDefinition>
<TextBlock Text="{Binding EmailCount}" Grid.Column="0" />
<TextBox Text="{Binding EmailAddress}" Grid.Column="1" />
</Grid>
</DataTemplate> I've just knocked this together in the CP post editor, so there may be some rough edges, but you should get the idea.
|
|
|
|
|
Ahh. Yes. I didn't quite understand that. I haven't done any Binding before, but looks pretty straightforward. I'm sure I can figure it out with your sample. I appreciate it.
I had actually created a ListBox and populated it with TextBlocks showing the Email #, but that's it. I couldn't figure out how to populate it with a second item TextBoxes. Binding looks like the answer.
|
|
|
|
|
It is really straightforward. I've no doubt you'll breeze through it.
|
|
|
|
|
Pete,
Stumped. I have the following Grid setup. 3 columns. Within Column 0, I have 5 rows. Within Column 0, Row 3, I have 2 more columns. It works. However, I can't get the 'EMAIL ADDRESSES' TextBlock to appear in Column 2. Even with Grid.Column = "0" Grid.Row = "2". Where does it need to be in the code? Also, if I want controls in Row 3, now I have a second Column constraint to deal with (Col 0, Row 3, Column 0 or 1). How do I deal with that? I tried naming the Grid, but it doesn't allow that type of syntax. I think that's only for C# code.
Sutton
<Grid Name="MiscGrid" ShowGridLines="True" Height="768" Width="1220">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="330"></ColumnDefinition>
<ColumnDefinition Width="700"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid Grid.Column="0" Name="C0Grid" ShowGridLines="True">
<Grid.RowDefinitions>
<RowDefinition Height="120"></RowDefinition>
<RowDefinition Height="180"></RowDefinition>
<RowDefinition Height="30"></RowDefinition>
<RowDefinition Height="300"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Grid Grid.Row="3" Name="R2Grid" ShowGridLines="True">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="60"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Height="20" HorizontalAlignment="Left" Margin="0,0,0,0" Text="EMAIL ADDRESSES" VerticalAlignment="Top" FontSize="16" />
</Grid>
</Grid>
</Grid>
|
|
|
|
|
Try putting Grid.Column="1" into the TextBlock, as the count is zero based. But, I think you are getting a bit confused as to how your grid looks. Reading through your Grid code, I get the following visualisation:
-----------------------------------------------------
| | | |
|---------------| | |
| | | |
|---------------| | |
| | | |
|---------------| | |
| | EA | | |
|---------------| | |
| | | |
|---------------|-----------------|-----------------| EA represents the Email Addresses textblock. Try setting each Grid Background to a different colour, and you'll see what I mean.
|
|
|
|
|
You are correct. That's what it looks like, except not to scale. I have this test code running in Visual C#. I wanted to put the 'EMAIL ADDRESSES' TextBlock in Row 2 as a header. But, I figured it out. You have to put the TextBlock code BEFORE the redefinition of the Row 3 Grid. That actually makes sense. I'm guessing Row 2 is out of scope once Row 3 is redefined into 2 columns.
BTW, I come from the embedded world of 25+ years, but not much Windows programming. I'm just dangerous enough to get a basic software app working in Visual C#. But, with fairly basic controls. I'm now trying to enhance the app with a few more complex controls.
Thanks for your advice.
|
|
|
|
|
No problem. Glad I can be of help.
|
|
|
|
|
Pete,
I took a different approach. I'm trying to create a ListBox on the fly without using any XAML code. I got it working - almost. What I have is an array of TextBoxes of 'Zone Descriptions'. I can put those into the ListBox as ListBoxItems, and it works great - no problem.
I want to add at the front of the TextBox a TextBlock or header that says 'Zone 1' or whatever the zone is along with the TextBox, which is user changeable. I have an array of TextBlocks. But, I can't (or don't know how to) adjust the ListBoxItem.Content to hold both the TextBlock and TextBox combo. LBI[i].Content = TBlkZoneDesc[i] + TBxZoneDesc[i] is what I want to do, but that syntax is not allowed. Doing either one separately works fine, but not both.
Do you have a suggestion on how to do that?
Sutton
ListBox LBZoneDesc = new ListBox();
LBZoneDesc.Width = 300;
LBZoneDesc.Height = 240;
Grid.SetColumn(LBZoneDesc,0);
Grid.SetRow(LBZoneDesc,2);
ListBoxItem[] LBI = new ListBoxItem[64];
for (byte i = 0; i < 5; i++)
{
LBI[i] = new ListBoxItem();
LBI[i].Padding = new Thickness(2);
LBI[i].Content = TBxZoneDesc[i];
LBZoneDesc.Items.Add(LBI[i]);
}
C0Grid.Children.Add(LBZoneDesc);
|
|
|
|
|
Hello all. I need a little help. It's necessary for project which's my friend and I are doing in current moment. Our program's hm...how can I say... We're doing book in WPF, but we're stuck on flip page animation. I know that there are a lotta codes on Internet and blogs where is flip page animation's described, but no one of it didn't help us and program doesn't work. And by the way, we wanna do flip animation like... A minute. Imagine a real book with text and you turn her on the next page. So, how can it be realized?
|
|
|
|
|
Hi
I needed a custom ComboBox control with a DataGrid as popup. I managed to change the MSDN example and everything works except I can't set ComboBox.IsDropDownOpen property from the
Trigger.
It it usefull also for setting ComboBox.Text property with the text selected from the DataGrid.
The problem is at the end near comments:
Property="ComboBox.IsDropDownOpen" Value="False"
(this line does not have any affect because the comboBox is not identified by name or style type).
Somehow I need to specify the comboBox style..
Any ideas how to do it?
RelativeSource with TemplateParent..
<pre lang="HTML">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ComboBox">
<Grid>
<ToggleButton
Name="ToggleButton"
Template="{StaticResource ComboBoxToggleButton}"
Grid.Column="2"
Focusable="false"
IsChecked="{Binding Path=IsDropDownOpen,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}"
ClickMode="Press">
</ToggleButton>
<ContentPresenter
Name="ContentSite"
IsHitTestVisible="False"
Content="{TemplateBinding SelectionBoxItem}"
ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
Margin="3,3,23,3"
VerticalAlignment="Center"
HorizontalAlignment="Left" />
<TextBox x:Name="PART_EditableTextBox"
Style="{x:Null}"
Template="{StaticResource ComboBoxTextBox}"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Margin="3,3,23,3"
Focusable="True"
Background="Transparent"
Visibility="Hidden"
IsReadOnly="{TemplateBinding IsReadOnly}"/>
<Popup Name="Popup" Placement="Bottom" IsOpen="{TemplateBinding IsDropDownOpen}" AllowsTransparency="True" Focusable="False" PopupAnimation="Slide">
<Grid Name="DropDown" SnapsToDevicePixels="True" MinWidth="{TemplateBinding ActualWidth}" MaxHeight="{TemplateBinding MaxDropDownHeight}">
<Border
x:Name="DropDownBorder"
Background="{StaticResource WindowBackgroundBrush}"
BorderThickness="1"
BorderBrush="{StaticResource SolidBorderBrush}"/>
<DataGrid
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
ItemsSource="{TemplateBinding ItemsSource}"
AutoGenerateColumns="False"
IsReadOnly="True"
GridLinesVisibility="None"
Background="LightGray"
RowBackground="LightBlue"
AlternatingRowBackground="LightCyan"
SelectedItem="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}, Path=SelectedIndex}">
<DataGrid.Columns>
<DataGridTextColumn
Header="Name"
MinWidth="150"
Binding="{Binding Path=Name}"/>
<DataGridTextColumn
Header="Address"
MinWidth="200"
Binding="{Binding Path=Address}"/>
</DataGrid.Columns>
<DataGrid.CellStyle>
<Style TargetType="DataGridCell">
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<!-- try to access directly parrent property-->
<Setter Property="ComboBox.IsDropDownOpen" Value="False"/>
</Trigger>
</Style.Triggers>
</Style>
|
|
|
|
|
Hi there, I have this XML file:
="1.0"="utf-8"
<Wpf>
<wpfctrl id="NavBtnTemplate">#FFCFDEFF</wpfctrl>
</Wpf>
and i want to bind Fill property of My Rectangle to value of wpfctrl node with id="NavBtnTemplate". How I can achieve this? Actually I have this rectangle inside my custom UserControl's Control Template. But hope that will not be the problem since I can bind to the properties of elements inside UserControl:
My UserControl (actually is very simple)
<UserControl.Resources>
<ControlTemplate x:Key="WpfWebSparkNavTemplate" TargetType="{x:Type Button}">
<Grid x:Name="controlLayout" Height="29.648" Width="84.284">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver"/>
<VisualState x:Name="Pressed"/>
<VisualState x:Name="Disabled"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Rectangle x:Name="rectangle"Fill="#FFCFDEFF" Margin="0" Height="31" d:LayoutOverrides="VerticalAlignment" >
</Rectangle>
<Label x:Name="buttonCaption" VerticalAlignment = "Center"
HorizontalAlignment = "Center"
FontWeight = "Bold" FontSize = "12" Content="{TemplateBinding Content}"/>
</Grid>
</ControlTemplate>
</UserControl.Resources<UserControl.Resources>
<ControlTemplate x:Key="WpfWebSparkNavTemplate" TargetType="{x:Type Button}">
<Grid x:Name="controlLayout" Height="29.648" Width="84.284">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver"/>
<VisualState x:Name="Pressed"/>
<VisualState x:Name="Disabled"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Rectangle x:Name="rectangle"Fill="#FFCFDEFF" Margin="0" Height="31" d:LayoutOverrides="VerticalAlignment" >
</Rectangle>
<Label x:Name="buttonCaption" VerticalAlignment = "Center"
HorizontalAlignment = "Center"
FontWeight = "Bold" FontSize = "12" Content="{TemplateBinding Content}"/>
</Grid>
</ControlTemplate>
</UserControl.Resources>
>
I did not found Blend wizard to allow me to state such filters on XML
Please help. Thank you.
modified 13-Mar-12 3:41am.
|
|
|
|
|
How can i do a interactions between models in PRISM V4 (unity+WPF) ?
please give me a examples if you can!!
|
|
|
|
|
I have a grid with 3 defined columns. Is there a way to divide column 1 into 3 grid rows without affecting the other 2 columns? I've tried defining RowDefinitions, but it spans all 3 columns. I don't want that. I only want it to affect the 1 column.
|
|
|
|