|
Hi, I am looking for ideas. Have to create controls dynamically and store values of textbox, combobox in database. Suppose I will give number 5 in existing textbox then it should create 5 textboxes and 5 combobox dynamically, all values of controls also have to save. Please share yours ideas. Thanks
|
|
|
|
|
|
Good tutorial, but my thing is have to create controls and take input from dynamically created controls.
|
|
|
|
|
You really need to provide a lot more detail about what problems you are having in implementing this.
|
|
|
|
|
foreach (TabItem ti in MainWindow.mw.tcMain.Items)
{
if (Convert.ToInt16(ti.Tag) == r.id)
{
MainWindow.mw.tcMain.SelectedItem = ti;
return;
}
}
|
|
|
|
|
That code selects the TabItem whose Tag is an int16 value that matches r.id.
The Tag property is present in many controls and is a custom user value not used by Wpf. You can use it to store an object of your choice and perform your custom logic based on it, for example save the original id such as in this code
|
|
|
|
|
|
Hi!
I have read along with this article [^]regarding WPF applications with Markup extensions.
In the end of the article there is the section called Custom Markup Extension example which I have tried and got working. The XAML code for the example confuse me.
In the articles C# code there is the ReflectionExtension class
public class ReflectionExtension : MarkupExtension
{
...
}
But in the XAML code there is no reference to ReflectionExtension instead there is a refence to Reflection.
<ListBox ItemsSource="{local:Reflection {x:Type Grid},
IncludeMethods=true, IncludeFields=true, IncludeEvents=true}"
MaxHeight="200" Grid.Row="3" Grid.ColumnSpan="2" />
I cannot find any reference what so ever in the article for Reflection, but somehow the example manage to reference to ReflectionExtension, compile and run.
If I rename the ReflectionExtension to MagicClass I must re-build the entire solution and change the XAML to:
<ListBox ItemsSource="{local:MagicClass{x:Type Grid},
IncludeMethods=true, IncludeFields=true, IncludeEvents=true}"
MaxHeight="200" Grid.Row="3" Grid.ColumnSpan="2" />
...or else the solution will not compile.
Is there a simple explanation for this?
I also have a further question regarding Markup Extensions.
In my company we have a language project which have classes deriving the MarkupExtension class. This gives the possibility in design time of XAML to
show different language text for buttons, labels and whatever other UIElement control that can display a text. The interesting is that I can switch language while in design-time and the XAML automatically display the selected language's text.
Unfortunately I cannot give away a example of this source code and might give me an explain how this works, but the XAML code I use is this:
<Button Content="{l:Lang Key=20}" \>
The "l" is the namespace reference xmlns:l="clr-namespace:namespace;assembly=assembly".
The "lang" must be a reference to a class deriving the MarkupExtension class. But I have search in the entire project for "lang" and cannot find ANY reference to it what so ever.
The "Key=20" is a reference to a the current language file with indices. In the my example there must be an index with value 20 which contain some text for whatever language is selected.
Without having the source code, can someone explain this?
Best regards,
/Steffe
|
|
|
|
|
Steffe - MarkupExtensions apply a little bit of magic here. If you add Extension to the end of your MarkupExtension class, you can leave this out of your XAML and the compiler will pick up which one you're trying to use.
As to your other question, is there a class called LangExtension in there by any chance?
|
|
|
|
|
Thanks for the reply Pete!
I will check that tomorrow if some class is named "LangExtension". I know there are two classes deriving the MarkupExtension class, so one of the must it be.
Another question: Is the MarkupExtension class meant to execute XAML code in design-time as well as runtime? The example I give with language project, in my original post, gives me a HUGE advantage when creating GUIs.
I have tried to understand the documentation of Markup extension on MSDN[^] but it is to big to scope, to generalized explaination and no obvious super easy example
Any suggestion of source which I can study?
/Steffe
|
|
|
|
|
Mc_Topaz wrote: Another question: Is the MarkupExtension class meant to execute XAML code in design-time as well as runtime? Well, that's the thing. Basically, in order to render a view of your UI in the designer, your code is periodically compiled and a new "snapshot" instance of the UI is rendered into place. This means that you get a version of a running app displayed, so it renders a design time view that just happens to have been created from a runtime version. So yes, your MarkupExtension will run.
Ooh, a simple MarkupExtension. Now, that's a thing. The good Dr WPF has some great examples here[^] that might shed some light for you.
However, a point for you to ponder - the use of {...} in XAML indicates that there's a MarkupExtension in there. So, whenever you see Binding, StaticResource, DynamicResource, etc, these are all markup extensions - indeed, if you were to look in the Object Browser, you would see they all have Extension after them - so it's BindingExtension, etc.
|
|
|
|
|
Pete O'Hanlon wrote: so it's BindingExtension, etc.
Actually, Binding is one of the ones that doesn't have the ...Extension suffix.
The *Extension naming pattern is for convenience and consistency. It is not necessary in order for a XAML processor to identify that class as support for a markup extension. So long as your codebase includes System.Xaml and uses .NET Framework XAML Services implementations, all that is necessary to be recognized as a XAML markup extension is to derive from MarkupExtension and to support a construction syntax.
WPF defines markup extension-enabling classes that do not follow the *Extension naming pattern, for example Binding . Typically the reason for this is that the class supports scenarios beyond pure markup extension support. In the case of Binding , that class supports run-time access to methods and properties of the object for scenarios that have nothing to do with XAML.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I guess I should read the documentation some time
|
|
|
|
|
I am implementing (soon on CodePlex) a.. MenuRibbon control (both menu and ribbon)
Anyway, I am now trying to implement the resizing behavior of a RibbonTab, and need some ideas...
I even downloaded the official open source version of the WPF Ribbon from MS[^], but it is very slow resizing (at least the open source version). Further the resizing code is somehow hard to follow, I found...
I identified that:
- A RibbonTab is an ItemsControl of RibbonGroup
- RibbonGroup have discrete sizes (i.e. large, medium, small for example) or... star size (which means it has a min, a max, and many value in between which are somehow difficult to determine (it's a property of its children possible value of visual tree, it happen when there is gallery in the RibbonGroup for example)). All RibbonGroup have a last smallest possible size of collapsed.
now I need an algorithm which choose a size combination for each control which choose a nice visual combination of these know (discrete) and unknown (star) sizes...
I am probably tired.. but I have blank page problem right now...
[EDIT] Time for bed! At any rate I think I know my biggest Hurdle, I need to put these size definition in C#, and while the StarSize is only one item in the possible size definition, it should contains a list of discrete value itself.
After that I'll be back to multiple list of size (i.e. discrete and finite) from which I just have to pick one value in each for most aesthetically pleasant result....
modified 8-Jul-14 10:33am.
|
|
|
|
|
Hi
I have a listview (gridview) and I want to show the items side by side if there are more than x items in the collection.
Something like this:
With few items
Item1
Item2
Item3
Item4
With more than x items
Item1 Item5 Item9
Item2 Item6 Item10
Item3 Item7 Item11
Item4 Item8 Item12
How can that be done in xaml?
|
|
|
|
|
If you know the height of your items, wrap them in a WrapPanel with the Orientation set to Vertical based on n * the height of the item.
|
|
|
|
|
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
|
|
|
|
|