|
In winforms there is an onclosing, I wonder if there is the same on a view. I used that in this article[^].
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I'd like to create this[^] blue area on a window.
I'm thinking a border to start with, but as far as the gradient, I'm not sure how to do that.
Any suggestions?
Everything makes sense in someone's mind
|
|
|
|
|
Heres a thought, why don't you download the source code from the example and chase through the style/xaml. Assuming of course that Karl has not supplied it as a theme.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Look at the XAML sections headed LinearGradientBrush .
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Hello,
I have an object with 3 properties- Field, Value, Operator. Also i have a list of this objects.
In my DataGrid i have an operator column which is static.
All other columns are added dynamically using dependency properties (adding column from the object - using Field Attribute).
The same object contains the value so the value will be presented in the cell under the right column (Field) .
All objects that have the same operator will be presented in one row in the DataGrid.
How can i do it? How do i use Dependency properties for this (if i need)?
|
|
|
|
|
|
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);
|
|
|
|