|
Thanks and that did the trick
|
|
|
|
|
I have a custom Panel with custom controls which should resize like RibbonButton, i.e. as the available size vary I should remove / add a header, resize an inner picture, etc...
Further the custom controls are lookless control, i.e. UI/Template is defined in the style, and I use triggers to update template element.
I communicate size setting from the panel to the individual controls by using an inherited attached property (I mean UI inheritance, like DataContext)
When I do my multi pass MeasureOverride() in my panel, when I call child.Measure(), it's as if my items are always the same size!!
Despite me changing the inherited attached property (and it does update inside control!)
To be clear my inside control don't resize, but when I change the inherited property, they change their UI template (to a smaller version)
Any clue how I can successfully implement RibbonButon and RibbonGroupPanel like behavior?
EDIT I just fixed my sample!
To give you an idea here is the code for the shorter sample I could write:
Size123Panel & Size123Control
public class Size123Control : Control
{
static Size123Control()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(Size123Control), new FrameworkPropertyMetadata(typeof(Size123Control)));
}
}
public class Size123Panel : Panel
{
public static int GetSize123(DependencyObject obj) { return (int)obj.GetValue(Size123Property); }
public static void SetSize123(DependencyObject obj, int value) { obj.SetValue(Size123Property, value); }
public static readonly DependencyProperty Size123Property = DependencyProperty.RegisterAttached(
"Size123", typeof(int), typeof(Size123Panel),
new FrameworkPropertyMetadata(3,
FrameworkPropertyMetadataOptions.Inherits
| FrameworkPropertyMetadataOptions.AffectsMeasure
| FrameworkPropertyMetadataOptions.AffectsParentMeasure
| FrameworkPropertyMetadataOptions.AffectsArrange
| FrameworkPropertyMetadataOptions.AffectsParentArrange
));
protected override Size ArrangeOverride(Size finalSize)
{
double hTot = 0, h = 0, x = 0, xMax = 0;
foreach (UIElement child in Children)
{
var cs = child.DesiredSize;
if (x > 0 && x + cs.Width > finalSize.Width)
{
hTot += h;
x = 0;
h = cs.Height;
}
else
{
if (cs.Height > h)
h = cs.Height;
}
child.Arrange(new Rect(new Point(x, hTot), cs));
x += cs.Width;
if (x > xMax)
xMax = x;
}
return new Size(xMax, hTot + h);
}
protected override Size MeasureOverride(Size availableSize)
{
Func<Size> measure = () =>
{
double hTot = 0, h = 0, x = 0, xMax = 0;
foreach (UIElement child in Children)
{
child.Measure(availableSize);
var cs = child.DesiredSize;
if (x > 0 && x + cs.Width > availableSize.Width)
{
hTot += h;
x = 0;
h = cs.Height;
}
else
{
if (cs.Height > h)
h = cs.Height;
}
x += cs.Width;
if (x > xMax)
xMax = x;
}
return new Size(xMax, hTot + h);
};
SetSize123(this, 3);
var s1 = measure();
if (s1.Width <= availableSize.Width && s1.Height <= availableSize.Height)
return s1;
SetSize123(this, 2);
var s2 = measure();
if (s2.Width <= availableSize.Width && s2.Height <= availableSize.Height)
return s2;
SetSize123(this, 1);
var s3 = measure();
Console.WriteLine("Size123: {0}, {1}, {2}", s1, s2, s3);
return s3;
}
}
generic.xaml
<Style TargetType="{x:Type local:Size123Control}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:Size123Control}">
<Border x:Name="MAIN" Width="48" Height="48" Background="Red" BorderThickness="1" BorderBrush="LightGray"/>
<ControlTemplate.Triggers>
<Trigger Property="local:Size123Panel.Size123" Value="2">
<Setter TargetName="MAIN" Property="Background" Value="Green"/>
<Setter TargetName="MAIN" Property="Width" Value="32"/>
<Setter TargetName="MAIN" Property="Height" Value="32"/>
</Trigger>
<Trigger Property="local:Size123Panel.Size123" Value="1">
<Setter TargetName="MAIN" Property="Background" Value="Blue"/>
<Setter TargetName="MAIN" Property="Width" Value="16"/>
<Setter TargetName="MAIN" Property="Height" Value="16"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
And the test window:
<local:Size123Panel>
<local:Size123Control/>
<local:Size123Control/>
<local:Size123Control/>
<local:Size123Control/>
<local:Size123Control/>
<local:Size123Control/>
<local:Size123Control/>
<local:Size123Control/>
<local:Size123Control/>
<local:Size123Control/>
<local:Size123Control/>
<local:Size123Control/>
<local:Size123Control/>
</local:Size123Panel>
If you look the console, when there is not enough space and control are shrunk, all 3 computed size are the same!
modified 3-Jul-14 5:48am.
|
|
|
|
|
Hi ,
I am using the following code to form a cube. It uses triangles for each face. How can I make a rectangular box by modifying its values. I dont have much idea on the indices property used here.
<GeometryModel3D.Geometry>
<MeshGeometry3D
Positions = "-1,-1,1 1,-1,1 1,1,1 -1,1,1"
TriangleIndices = "0 1 2 2,3,0"
TextureCoordinates="0,1 1,1 1,0 0,0"
/>
</GeometryModel3D.Geometry>
Thanks and Regards
Subin
|
|
|
|
|
It is explained pretty well on MSDN in:3-D Graphics Overview[^]
The section on Model and Mesh Primitives explains how the Positions and TriangleIndices relate. (Although it says there are twelve groups of three indices in the example, only two are actually there...)
A positive attitude may not solve every problem, but it will annoy enough people to be worth the effort.
|
|
|
|
|
I have just started learning WPF and read about XAML. I want to know if XAML is used anywhere also apart from WPF ? Can it be used with Java or any other language ?
|
|
|
|
|
Member 9719359 wrote: I want to know if XAML is used anywhere also apart from WPF ? Silverlight. Windows Phone. Windows Store Apps. Xamarin uses a variant for their cross platform work with Android and iOS.
|
|
|
|
|
I have an Expander in a ListItem data template.
When the Expander is collapsed, it minimizes horizontally to left so it's collapsed with is small. How can I set it so that with doesn't changed when collapsed?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
What have you set your ExpandDirection to? Try setting it to Down .
|
|
|
|
|
Hi,
I am new to prism framework. So I created a Obervable collection for datagrid. So When i poulated it the view was also affected and it showed whatever the chnge was.
But when i use on a single variable the value is not chnaged in the view. So can you help me to sort out this issue
|
|
|
|
|
The only really remarkable thing about an ObservableCollection is that it implements INotifyCollectionChanged. This interface contains a CollectionChanged event when the number of items in the collection is changed somehow. When WPF sees that an item it is binding to implements this interface, it knows that it can listen to this event.
Okay, so that's the ObservableCollection. Why did I bring it up? Well, that's because the collection changing is taken care of for you by a custom collection. Property changes, on the other hand, aren't handled automatically for you. When you think about it, you can see why this is desirable. Would you really want WPF to be listening for changes on every property you've bound it to, even if those properties are straightforward primitives. Implementing automatic change binding on these would put a tremendous strain on your application because you would potentially be wiring up many items that you don't want to. So, how do you do property change notification? Well, in just the same way you have INotifyCollectionChanged, there's a property change interface that WPF understands called INotifyPropertyChanged. This interface has a PropertyChanged event that you raise to tell WPF that a particular item has changed (by passing the name of the item that changed, or an empty string if you want WPF to refresh all properties).
Now, if you've heard of MVVM, you're probably aware of a concept called a ViewModel. The ViewModel is intended to isolate the View from the Model. It's a common implementation pattern that has a BaseViewModel class that handles the INotifyPropertyChanged (often abbreviated to INPC). So, the base VM would look something like this:
public abstract class BaseViewModel : INotifyPropertyChanged
{
protected void NotifyOfChange(string property)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler == null) return;
handler(this, new PropertyChangedEventArgs(property));
}
public event PropertyChangedEventHandler PropertyChanged;
} So, your derived VM would possibly look something like this:
public class MyViewModel : BaseViewModel
{
private int _onlineCount;
public int OnlineCount
{
get { return _onlineCount; }
set
{
if (_onlineCount == value) return;
_onlnieCount = value;
NotifyOfChange("OnlineCount");
}
}
}
|
|
|
|
|
I ve given like this. Should I inherit the view model class in the xaml.cs file.
The rest above i ve written as such in my project. But still not changing
|
|
|
|
|
Member 10053752 wrote: I ve given like this. Should I inherit the view model class in the xaml.cs file No.
Without seeing any of your code, it's difficult to see what the issue is.
|
|
|
|
|
if u can give me your mail id i can share my project with you
|
|
|
|
|
I can mail my project t u .. but can u give me ur mail id I can share it
|
|
|
|
|
Hello everyone
In my WPF project I have created a UserControl (this is called Applic.xaml), and within this usercontrol I have placed a nested UserControl (this is called PasswordScreen.xaml). Here is the xaml design code of Applic.xaml usercontrol:
<UserControl xmlns:my2="clr-namespace:iPosCloud.com.iposcloud.uiC_.views"
x:Class="iPosCloud.com.iposcloud.main.Applic"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:my0="clr-namespace:iPosCloud.com.iposcloud.main"
xmlns:Intersoft="http://intersoft.clientui.com/schemas"
xmlns:my1="clr-namespace:Intersoft.Client.UI.Controls;assembly=Intersoft.Client.UI.Controls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="800" d:DesignWidth="1024" xmlns:my="http://schemas.microsoft.com/surface/2008">
<UserControl.Background>
<ImageBrush ImageSource="/iPosCloud;component/images/HoneyComb.png" Stretch="Fill" TileMode="Tile" Viewport="0,0,46,25" ViewportUnits="Absolute" />
</UserControl.Background>
<UserControl.Resources>
<DropShadowEffect x:Key="DropShadowEffect" ShadowDepth="0.1" Direction="360" BlurRadius="3" Opacity=".5" />
</UserControl.Resources>
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Name="MainGridApplic">
<Border BorderThickness="2" HorizontalAlignment="Left" Name="border1" VerticalAlignment="Stretch" Margin="4" BorderBrush="{x:Null}">
<Border.BitmapEffect>
<DropShadowBitmapEffect Color="Black" Direction="360" ShadowDepth="10" Opacity=".5" Softness="9" />
</Border.BitmapEffect>
<Intersoft:UXGridPanel Margin="2" Column="1" Row="1" ItemHeight="220" ItemWidth="1190" Name="UXGridPanelLeft">
<Image Name="image1" Source="/iPosCloud;component/images/Logo.png" Width="1000" HorizontalAlignment="Left" />
</Intersoft:UXGridPanel>
</Border>
<Grid Margin="2" HorizontalAlignment="Right">
<my2:PasswordScreen /> "HERE IS THE UserControl THAT I PLACED..."
</Grid>
</Grid>
</UserControl>
In PasswordScreen.xaml usercontrol there is a button (called Login). On the click event when clicked, I want to call another xmal file called SwitchboardView.xaml and display it within the (Applic.xaml usercontrol) but it is not firing nothing and the code behind this button is:
private void btnLogin_Click(object sender, RoutedEventArgs e)
{
SwitchboardView sbv = new SwitchboardView();
Applic ap = new Applic();
ap.MainGridApplic.Children.Add(sbv);
}
Could someone please help me solve this problem with the sample of code (what am I doing wrong...)
Kind regards
Lapeci
|
|
|
|
|
Hi friends,
In Silverlight Web Application, how to display/call an .aspx page in a Frame or any other control when click on a link button?
Please solve my problem ASAP.
Thanks,
Raviteja
|
|
|
|
|
give me introduction about silverlight
|
|
|
|
|
Well, a few years ago, this really great guy called David Silverlight ran community sites for.NET developers. One day, he was invited to spend some time with Bill Gates who said he wanted to name a product after him to thank him for his work in the online.NET community. Fortunately they chose to use his second name.
|
|
|
|
|
heheheheh, some things never change!
|
|
|
|
|
What? Whistles innocently.
This story may or may not be[^] true. David's a friend of mine, and is a truly great guy.
|
|
|
|
|
Seriously I didn't know this. Thanks Pete
|
|
|
|
|
|
Hey guys i need help with a program im working on.
<u>Problem:</u> i have no idea how to get it to work, im still new to developing apps
<u>What needs to be done:</u>
I have two WPF Windows, one is for entering information which will load the entered info into the second window.
And depending on what option selected in the combobox it must load a logo at the top of the second window and its related address below it.
Thanks
The Layout:
Mainwindow:
<Window x:Class="Other_Stuff.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Entry Form" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition Height="45"></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120"></ColumnDefinition>
<ColumnDefinition Width="7*"></ColumnDefinition>
<ColumnDefinition Width="36*"/>
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Grid.Row="0" Content="Client"></Label>
<Label Grid.Column="0" Grid.Row="2" Content="Pharmacy" Margin="-5,5,5,5"></Label>
<Label Grid.Column="0" Grid.Row="3" Content="Script Number"/>
<Button x:Name="Submit" Grid.Column="0" Grid.Row="4" Content="Submit" Click="Button_Click"/>
<TextBox Name="client" Grid.Column="1" Grid.Row="0" Grid.ColumnSpan="2"></TextBox>
<ComboBox Name="PharmacyComboBox" Grid.Column="1" Grid.Row="2" Grid.ColumnSpan="2" Margin="0,0,0,10" >
<ComboBoxItem Content="Dischem" ></ComboBoxItem>
<ComboBoxItem Content="Clicks" MouseLeftButtonUp="ComboBoxItem_MouseLeftButtonUp"></ComboBoxItem>
</ComboBox>
<TextBox Name="Scriptnumber" Grid.Column="1" Grid.Row="3" Grid.ColumnSpan="2" Height="55" VerticalAlignment="Top" Margin="5,0,0,0">
</TextBox>
<Label Content="Medicine" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,10,0,0" Grid.Row="1"/>
<ListBox Grid.Column="1" HorizontalAlignment="Left" Height="45" VerticalAlignment="Top" Width="397" Grid.ColumnSpan="2" Grid.Row="1" Name="medlist" Margin="0,5,0,0" Grid.RowSpan="2"/>
<!--<Button Content="Submit" Grid.Column="1" Grid.Row="5" Click="Button_Click" Grid.ColumnSpan="2"></Button>-->
</Grid>
</Window>
ScriptWindow:
Window x:Class="Other_Stuff.Script"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Script" Height="488.06" Width="437.313" Loaded="Window_Loaded">
<Grid>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition Height="45"></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120"></ColumnDefinition>
<ColumnDefinition Width="7*"></ColumnDefinition>
<ColumnDefinition Width="36*"/>
</Grid.ColumnDefinitions>
<Image Grid.Column="0" Grid.Row="0" Name="LogoImage" Grid.ColumnSpan="3" Margin="0,2,0,43" Grid.RowSpan="2"></Image>
<Label Grid.Row="1" Grid.RowSpan="2" Name="AdresslbLabel" Grid.ColumnSpan="3"/>
<Label Grid.Column="0" Grid.Row="3" Grid.ColumnSpan="3" Name="ScripTextBox"></Label>
<DataGrid Grid.Column="0" Grid.Row="4" Grid.ColumnSpan="3"/>
<TextBox Grid.Column="0" Grid.Row="4" Grid.ColumnSpan="3" Name="RelatedTextBox"/>
<Image Grid.Column="0" Grid.Row="5" Grid.ColumnSpan="3" Grid.RowSpan="2" Name="AdverTextBox"/>
<Button Content="Button" HorizontalAlignment="Left" Margin="10,10,0,0" Grid.Row="7" VerticalAlignment="Top" Width="100" Height="39" Click="Button_Click"/>
</Grid>
</Window>
|
|
|
|
|
You are treating this like a winforms application, STOP. Do some reading on MVVM and data binding if you wish to continue using WPF or actually use winforms.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I got a combo box in wpf form I set the ItemSource to the collection of Dictionary of (Pet Type) and just display the Value and hid the Key
public void BindComboBoxes()
{
this.cboTypes.ItemsSource = new BindingSource(CommonMgr.GetPetTypesDropDown(false), null);
this.cboTypes.DisplayMemberPath = "Value";
this.cboTypes.SelectedValuePath = "Key";
}
Then whenever I type to encode a new Breed Object, and type a text in the cboTypes of something that doesn't exist in its items(not in the db), my program will ask if the end user wants to add that new PetType in the db, if yes, then it will do so.
Then i update the cboTypes using the BindComboBoxes method again, set the cboTypes.Text into the new item and assign the Key to the designated field, but the problem is, it says, it was null. it worked fine in the windows form though. Here's my code:
public Breed GetPageEntity()
{
Breed setEntity = new Breed();
bool doesExist = false;
setEntity.Id = DefaultValue.GetInt(this.txtId.Text);
setEntity.BreedName = DefaultValue.GetString(this.txtName.Text);
try
{
setEntity.PetTypeId = DefaultValue.GetInt(this.cboTypes.SelectedValue.ToString());
}
catch (Exception)
{
var addAnother = MessageBox.Show(String.Format("{0}: This type is not in the database. \nAdd {0} to the database?",
this.cboTypes.Text), "Pet Type Cannot Be Found", MessageBoxButtons.OKCancel);
if (addAnother == System.Windows.Forms.DialogResult.OK)
{
petTypeMgr.Entity = this.PetTypeAdder(cboTypes.Text);
string temp = this.cboTypes.Text;
petTypeMgr.Insert((petTypeMgr.Entity), fUser.Entity.Id, ref doesExist);
BindComboBoxes();
cboTypes.Text = temp;
setEntity.PetTypeId = DefaultValue.GetInt(this.cboTypes.SelectedValue);
}
}
setEntity.Description = DefaultValue.GetString(this.txtDescription.Text);
setEntity.SortOrder = DefaultValue.GetInt(txtSortOrder.Text);
setEntity.StatusId = true;
return setEntity;
}
|
|
|
|
|