I had a working user control done in WPF in XAML. Now I have removed the XAML and created the usercontrol with code because I need to inherit from this control. Previosuly I had code like this one on the code using the control:
<mc:MyControl Foreground="White">
And all the controls inside the MyControl control used this Foreground setting. Now that I've created the control just using C# this is not happening anymore.
Someone know why and how to fix this?
Thanks in advance.
EDIT:
This is the XAML:
<UserControl x:Class="Utils.Wpf.Chart.Chart"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
SizeChanged="UserControl_SizeChanged">
<Grid>
<Border Margin="5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Canvas Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="0" Grid.RowSpan="2" x:Name="DrawArea" Canvas.Background="Transparent" MouseEnter="DrawArea_MouseEnter" MouseLeave="DrawArea_MouseLeave" MouseMove="DrawArea_MouseMove" Cursor="None">
<Line x:Name="Border1" X1="0" X2="{Binding Path=ActualWidth, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Canvas}}}" Y1="{Binding Path=ActualHeight, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Canvas}}}" Y2="{Binding Path=ActualHeight, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Canvas}}}" StrokeThickness="1" Stroke="{Binding BorderBrush, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"/>
<Line x:Name="Border2" Y1="0" Y2="{Binding Path=ActualHeight, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Canvas}}}" X1="0" X2="0" StrokeThickness="1" Stroke="{Binding BorderBrush, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"/>
<TextBlock x:Name="CrossValue" Text="[-,-]" Foreground="#EBDE11" Visibility="Hidden"/>
</Canvas>
<TextBlock Grid.Column="0" Grid.Row="0" VerticalAlignment="Top" HorizontalAlignment="Right" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=MaxYCaption, TargetNullValue=MaxY}" Margin="3,0,6,0"/>
<TextBlock Grid.Column="0" Grid.Row="1" VerticalAlignment="Bottom" HorizontalAlignment="Right" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=MinYCaption, TargetNullValue=MinY}" Margin="3,0,6,0"/>
<TextBlock Grid.Column="1" Grid.Row="2" HorizontalAlignment="Left" VerticalAlignment="Top" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=MinX, TargetNullValue=MinX}" Margin="3,3,0,0"/>
<TextBlock Grid.Column="2" Grid.Row="2" HorizontalAlignment="Right" VerticalAlignment="Top" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=MaxX, TargetNullValue=MaxX}" Margin="0,3,3,0"/>
</Grid>
</Border>
</Grid>
</UserControl>
This is the C#:
_outerGrid = new Grid();
_border = new Border();
_innerGrid = new Grid();
_canvas = new Canvas();
_line1 = new Line();
_line2 = new Line();
_cursorText = new TextBlock();
_maxXText = new TextBlock();
_maxYText = new TextBlock();
_minXText = new TextBlock();
_minYText = new TextBlock();
this.Content = _outerGrid;
_border.Margin = new Thickness(5);
_border.HorizontalAlignment = HorizontalAlignment.Stretch;
_border.VerticalAlignment = VerticalAlignment.Stretch;
_outerGrid.Children.Add(_border);
_column1 = new ColumnDefinition();
_column1.Width = new GridLength(0, GridUnitType.Auto);
_column2 = new ColumnDefinition();
_column2.Width = new GridLength(1, GridUnitType.Star);
_column3 = new ColumnDefinition();
_column3.Width = new GridLength(1, GridUnitType.Star);
_row1 = new RowDefinition();
_row1.Height = new GridLength(1, GridUnitType.Star);
_row2 = new RowDefinition();
_row2.Height = new GridLength(1, GridUnitType.Star);
_row3 = new RowDefinition();
_row3.Height = new GridLength(0, GridUnitType.Auto);
_innerGrid.ColumnDefinitions.Add(_column1);
_innerGrid.ColumnDefinitions.Add(_column2);
_innerGrid.ColumnDefinitions.Add(_column3);
_innerGrid.RowDefinitions.Add(_row1);
_innerGrid.RowDefinitions.Add(_row2);
_innerGrid.RowDefinitions.Add(_row3);
_border.Child = _innerGrid;
_canvas.Background = Brushes.Transparent;
_canvas.Cursor = Cursors.None;
_canvas.MouseEnter += new MouseEventHandler(_canvas_MouseEnter);
_canvas.MouseMove += new MouseEventHandler(_canvas_MouseMove);
_canvas.MouseLeave += new MouseEventHandler(_canvas_MouseLeave);
Grid.SetColumn(_canvas,1);
Grid.SetColumnSpan(_canvas,2);
Grid.SetRowSpan(_canvas,2);
_innerGrid.Children.Add(_canvas);
_line1.X1 = 0;
_line1.StrokeThickness = 1;
Binding x2Binding = new Binding("ActualWidth");
x2Binding.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor) {AncestorType = _canvas.GetType()};
_line1.SetBinding(Line.X2Property, x2Binding);
Binding yBinding = new Binding("ActualHeight");
yBinding.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor) { AncestorType = _canvas.GetType() };
_line1.SetBinding(Line.Y1Property, yBinding);
_line1.SetBinding(Line.Y2Property, yBinding);
_line2.Y1 = 0;
_line2.X1 = 0;
_line2.X2 = 0;
_line2.StrokeThickness = 1;
Binding y2Binding = new Binding("ActualHeight");
y2Binding.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor) { AncestorType = _canvas.GetType() };
_line2.SetBinding(Line.Y2Property, x2Binding);
Binding strokeBinding = new Binding("BorderBrush");
strokeBinding.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor) { AncestorType = typeof(UserControl) };
_line2.SetBinding(Shape.StrokeProperty, strokeBinding);
_cursorText.Text = "[-,-]";
_cursorText.Foreground = new SolidColorBrush(Color.FromRgb(0xeb, 0xde, 11));
_cursorText.Visibility = Visibility.Hidden;
_canvas.Children.Add(_line1);
_canvas.Children.Add(_line2);
_canvas.Children.Add(_cursorText);
_maxYText.VerticalAlignment = VerticalAlignment.Top;
_maxYText.HorizontalAlignment = HorizontalAlignment.Right;
_maxYText.Margin = new Thickness(3, 0, 6, 0);
Binding maxYBinding = new Binding("MaxYCaption");
maxYBinding.TargetNullValue = "MaxY";
maxYBinding.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor) { AncestorType = typeof(UserControl) };
_maxYText.SetBinding(TextBlock.TextProperty, maxYBinding);
_minYText.VerticalAlignment = VerticalAlignment.Bottom;
_minYText.HorizontalAlignment = HorizontalAlignment.Right;
_minYText.Margin = new Thickness(3, 0, 6, 0);
Binding minYBinding = new Binding("MinYCaption");
minYBinding.TargetNullValue = "MinY";
minYBinding.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor) { AncestorType = typeof(UserControl) };
_minYText.SetBinding(TextBlock.TextProperty, minYBinding);
_maxXText.VerticalAlignment = VerticalAlignment.Top;
_maxXText.HorizontalAlignment = HorizontalAlignment.Right;
_maxXText.Margin = new Thickness(0, 3, 3, 0);
Binding maxXBinding = new Binding("MaxX");
maxXBinding.TargetNullValue = "MaxX";
maxXBinding.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor) { AncestorType = typeof(UserControl) };
_maxXText.SetBinding(TextBlock.TextProperty, maxXBinding);
_minXText.VerticalAlignment = VerticalAlignment.Top;
_minXText.HorizontalAlignment = HorizontalAlignment.Left;
_minXText.Margin = new Thickness(3, 3, 0, 0);
Binding minXBinding = new Binding("MinX");
minXBinding.TargetNullValue = "MinX";
minXBinding.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor) { AncestorType = typeof(UserControl) };
_minXText.SetBinding(TextBlock.TextProperty, minXBinding);
_innerGrid.Children.Add(_maxYText);
_innerGrid.Children.Add(_maxXText);
_innerGrid.Children.Add(_minYText);
_innerGrid.Children.Add(_minXText);
Grid.SetColumn(_maxXText, 2);
Grid.SetColumn(_minXText, 1);
Grid.SetRow(_minYText, 1);
Grid.SetRow(_minXText, 2);
Grid.SetRow(_maxXText, 2);
this.SizeChanged += new System.Windows.SizeChangedEventHandler(Chart2_SizeChanged);
#SoMoS - I think what you are talking about is a CustomControl, and not a UserControl. If so, did you apply a control template to your inherited control?
You can read about the differences between custom controls to user controls in here-
http://wangmo.wordpress.com/2007/09/28/user-controls-vs-custom-controls/
http://www.wpftutorial.net/CustomVsUserControl.html
If you will apply a control template to your custom control, you could manage its look just as you would with a User Control with XAML.
Related
I am beginner in WPF telerik technology framework.
I want custom colors to points in telerik scatter point chart. But colors of points are not changing. What should I do? Is there something fundamentally wrong in what I am doing?
Here is c# code
var pallate = ColorPallate();
var PS = new ScatterPointSeries();
var pallaet = new ChartPalette();
PaletteEntryCollection pall = new PaletteEntryCollection();
for (int i = 0; i < data.GetLength(0); i++)
{
ScatterDataPoint point = new ScatterDataPoint();
point.XValue = data[i, XAxisIndex];
point.YValue = data[i, YAaxisIndex];
int value = 0;
if (!float.IsNaN(PredictedResult[i]))
value = System.Convert.ToInt32(PredictedResult[i]);
var filler = new PaletteEntry();
filler.fill(pallate[value]);
pall.Add(filler);
PS.DataPoints.Add(point);
}
pallaet.SeriesEntries.Add(pall);
this.Cross_Plot.Palette = pallaet;
Where ColorPallate() provide custom color palatte as
private Brush[] ColorPallate()
{
var pallate = new Brush[15];
pallate[0] = new SolidColorBrush(Colors.Red);
pallate[1] = new SolidColorBrush(Colors.Orange);
pallate[2] = new SolidColorBrush(Colors.Green);
pallate[3] = new SolidColorBrush(Colors.Pink);
pallate[4] = new SolidColorBrush(Colors.Black);
pallate[5] = new SolidColorBrush(Colors.Brown);
pallate[6] = new SolidColorBrush(Colors.Crimson);
pallate[7] = new SolidColorBrush(Colors.DarkOrange);
pallate[8] = new SolidColorBrush(Colors.ForestGreen);
pallate[9] = new SolidColorBrush(Colors.Indigo);
pallate[10] = new SolidColorBrush(Colors.DarkKhaki);
pallate[11] = new SolidColorBrush(Colors.Purple);
pallate[12] = new SolidColorBrush(Colors.Gold);
pallate[13] = new SolidColorBrush(Colors.RosyBrown);
pallate[14] = new SolidColorBrush(Colors.Gray);
return pallate;
}
Here is XMAL code
<telerik:RadCartesianChart x:Name="Cross_Plot" Margin="0,51,17,0" VerticalAlignment="Top" Height="472" Grid.Column="2" HorizontalAlignment="Right" Width="1057" Grid.RowSpan="2" >
<telerik:RadCartesianChart.HorizontalAxis>
<telerik:LinearAxis SmartLabelsMode="SmartStep" MajorTickOffset="0"/>
</telerik:RadCartesianChart.HorizontalAxis>
<telerik:RadCartesianChart.VerticalAxis>
<telerik:LinearAxis SmartLabelsMode="SmartStep" ElementBrush="Black" />
</telerik:RadCartesianChart.VerticalAxis>
<telerik:ScatterPointSeries XValueBinding="XValue" YValueBinding="YValue" ItemsSource="{Binding}">
<telerik:ScatterPointSeries.DefaultVisualStyle>
<Style TargetType="Path">
<Setter Property="Fill" Value="{Binding RelativeSource={RelativeSource Mode=Self}, Path=Tag.DataItem.Color}" />
<Setter Property="Width" Value="10" />
<Setter Property="Height" Value="10" />
</Style>
</telerik:ScatterPointSeries.DefaultVisualStyle>
</telerik:ScatterPointSeries>
</telerik:RadCartesianChart>
<TextBlock Grid.Column="2" HorizontalAlignment="Left" Margin="131,37,0,0" TextWrapping="Wrap" Text="Well points on X Axis" VerticalAlignment="Top" Width="248"/>
<TextBlock Grid.Column="2" HorizontalAlignment="Left" Margin="389,35,0,0" TextWrapping="Wrap" Text="Well points on Y axis" VerticalAlignment="Top" Width="243"/>
I shall be very thankful to you for your efforts
You could use Telerik's PointTemplateSelector. This allows each point to be customized dynamically in code.
I have wired Manipulation events with the listviewitem to capture left swipe and right swipe. But when I try to scroll down the listview, it does not work! The manipulation events get fired and the listview does not scroll!
This is the listview Datatemplate
<Grid Height="60" Width="380" Margin="0,0,0,1">
<Grid x:Name="ItemGrid" HorizontalAlignment="Left" VerticalAlignment="Center" Width="380" Height="60" Background="Orange" Canvas.ZIndex="2"
ManipulationMode="TranslateX" ManipulationStarted="On_ChannelItem_ManipulationStarted" ManipulationDelta="On_ChannelItem_ManipulationDelta" ManipulationCompleted="OnChannelItemManipulationCompleted">
<TextBlock x:Name="titleTextBlock" Margin="20,0,0,0" Canvas.ZIndex="2" VerticalAlignment="Center" TextAlignment="Left" FontSize="25" >
</TextBlock>
</Grid>
<Grid x:Name="DelGrid" Opacity="0.0" HorizontalAlignment="Right" VerticalAlignment="Center" Height="60" Background="Red" Canvas.ZIndex="-1" Tapped="On_ChannelDelete_Tap" Width="380">
<Button Content="X" FontSize="25" Canvas.ZIndex="-1" VerticalAlignment="Center" HorizontalAlignment="Center" Width="380" BorderThickness="0" />
</Grid>
</Grid>
This is the manipulation events
private void OnChannelItemManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
{
Grid ChannelGrid = (Grid)sender;
Grid DeleteGrid = (Grid)((Grid)(ChannelGrid.Parent)).Children[1];
double dist = e.Cumulative.Translation.X;
if (dist < -100) // Swipe left
{
Storyboard SwipeLeft = new Storyboard();
DoubleAnimation OpacityAnimation = new DoubleAnimation();
OpacityAnimation.EnableDependentAnimation = true;
OpacityAnimation.From = 0.0;
OpacityAnimation.To = 1.0;
OpacityAnimation.BeginTime = TimeSpan.FromMilliseconds(0);
OpacityAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(1));
Storyboard.SetTarget(OpacityAnimation, DeleteGrid);
Storyboard.SetTargetProperty(OpacityAnimation, "Opacity");
SwipeLeft.Children.Add(OpacityAnimation);
DoubleAnimation WidthAnimation = new DoubleAnimation();
WidthAnimation.EnableDependentAnimation = true;
WidthAnimation.From = 380;
WidthAnimation.To = 0;
WidthAnimation.BeginTime = TimeSpan.FromMilliseconds(30);
WidthAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(100));
Storyboard.SetTarget(WidthAnimation, ChannelGrid);
Storyboard.SetTargetProperty(WidthAnimation, "Width");
SwipeLeft.Children.Add(WidthAnimation);
SwipeLeft.Begin();
}
else if (dist > 100) // Swipe right
{
Storyboard SwipeRight = new Storyboard();
ColorAnimation changeColorAnimation = new ColorAnimation();
changeColorAnimation.EnableDependentAnimation = true;
changeColorAnimation.To = Colors.Green;
changeColorAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(100));
Storyboard.SetTarget(changeColorAnimation, ChannelGrid);
PropertyPath p = new PropertyPath("(ChannelGrid.Background).(SolidColorBrush.Color)");
Storyboard.SetTargetProperty(changeColorAnimation, p.Path);
SwipeRight.Children.Add(changeColorAnimation);
SwipeRight.Begin();
}
}
How do I enable the normal listview scrolling as well as the swipe? Vertical Scrolling is possible when I remove the manipulation events
Update your manipulation mode to include System:
ManipulationMode="TranslateX,System"
I have a Grid which scaled/zoomed with ScaleTransform by slider. At runtime many UIElements are added to this Grid.
I want to show some tooltips, but not scaled! How should I do that?
For the example: Grid has scaleX and scaleY 2, so I set new ScaleTransform(0.5, 0.5), but didn't help. It seems that the most similar value is 0.740.. Why?
Even Grid's LayoutTransform.Inverse is set to scale values 0.5.
XAML:
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" Height="Auto" Width="Auto" Name="graphScrollViewer" ScrollChanged="graphScrollViewer_ScrollChanged">
<Grid Margin="0,0,0,0" Name="graphGrid" Width="Auto" Height="Auto" ScrollViewer.IsDeferredScrollingEnabled="True" MouseLeftButtonDown="graphGrid_MouseLeftButtonDown" MouseLeftButtonUp="graphGrid_MouseLeftButtonUp" MouseMove="graphGrid_MouseMove">
<Grid.LayoutTransform>
<ScaleTransform ScaleX="{Binding ElementName=sldZoom, Path=Value}" ScaleY="{Binding ElementName=sldZoom, Path=Value}" />
</Grid.LayoutTransform>
</Grid>
</ScrollViewer>
<Slider Minimum="0.1" Maximum="20" Value="1" x:Name="sldZoom" Panel.ZIndex="10" Orientation="Horizontal" VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="0,0,20,20" Height="23" Width="100" ValueChanged="sldZoom_ValueChanged"/>
Code-behind:
(method of Rectangle (MouseEnter event) dynamically added to grid)
private void rect_MouseEnter(object sender, MouseEventArgs e)
{
RectToolTip = new TextBlock();
RectToolTip.HorizontalAlignment = HorizontalAlignment.Left;
RectToolTip.VerticalAlignment = VerticalAlignment.Top;
RectToolTip.TextAlignment = TextAlignment.Center;
RectToolTip.Height = this.HeaderTwoHeight + 1;
RectToolTip.Text = " " + (RectsTasks[(sender as Rectangle)]).Info + " ";
RectToolTip.Background = this.ToolTipBackground;
RectToolTip.Foreground = this.ToolTipFontColor;
RectToolTipBorder = new Border();
RectToolTipBorder.Child = RectToolTip;
RectToolTipBorder.BorderThickness = new Thickness(this.ToolTipBorderThickness);
RectToolTipBorder.BorderBrush = this.ToolTipBorderColor;
RectToolTipBorder.Margin = new Thickness(e.GetPosition((graphGrid)).X + 10, e.GetPosition((graphGrid)).Y + 10, 0, 0);
RectToolTipBorder.VerticalAlignment = System.Windows.VerticalAlignment.Top;
RectToolTipBorder.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
graphGrid.Children.Add(RectToolTipBorder);
RectToolTipBorder.LayoutTransform = RectToolTip.LayoutTransform = new ScaleTransform(????);
Grid.SetZIndex(RectToolTip, 20);
Grid.SetZIndex(RectToolTipBorder, 20);
}
You need to assign the inverse transform to the child element, so that the child will stay intact.
RectToolTipBorder.LayoutTransform = graphGrid.LayoutTransform.Inverse as Transform;
How to place canvas with drawings inside certain column of a ListView control ?
I have this:
<DataTemplate>
<Canvas Width="60" Height="20" Background="Red" ClipToBounds="True" >
<ContentPresenter Content="{Binding Path=Graph}" />
</Canvas>
</DataTemplate>
and:
var canvas = new Canvas();
canvas.Children.Add(new Ellipse(){});
var items = new ObservableCollection<LvItem>() { new LvItem(){ Graph = canvas} };
myListView.ItemsSource = items;
but it shows System.Windows.Controls.Canvas as a text, and not the canvas itself with its drawings.
It's working, check example below.
XAML:
<ListView Name="myListView" >
<ListView.View>
<GridView>
<GridViewColumn Width="140" Header="Grap">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Canvas Width="60" Height="50" Background="Red" ClipToBounds="True" >
<ContentPresenter Content="{Binding Path=Graph}" />
</Canvas>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
LvItem class:
class LvItem
{
public Canvas Graph { get; set; }
}
Code-behind:
var canvas = new Canvas();
canvas.Children.Add(new Ellipse() { Width = 50, Height = 50, Fill = new SolidColorBrush(Colors.Yellow) });
var canvas2 = new Canvas();
canvas2.Children.Add(new Ellipse() { Width = 50, Height = 50, Fill = new SolidColorBrush(Colors.Blue) });
var items = new ObservableCollection<LvItem>() { new LvItem() { Graph = canvas }, new LvItem() { Graph = canvas2 } };
myListView.ItemsSource = items;
Result:
Why does the following C# code not produce the equivalent of my Silverlight code?
XAML
<Border CornerRadius="8" BorderBrush="White" Height="70" BorderThickness="4">
<StackPanel Orientation="Horizontal">
<Border Margin="5,0,0,0" BorderBrush="White" Height="45" Width="45" BorderThickness="2" CornerRadius="2" Background="White">
<Image Source="/Crystal%20Cloud;component/Resources/Images/weapons/swords/sword_0.png" />
</Border>
<StackPanel Margin="10,0,0,0">
<TextBlock Text="Wooden Dagger" FontFamily="Comic Sans MS" />
<TextBlock Text="DPS: 1" FontFamily="Comic Sans MS" FontSize="16" Margin="15,0,0,0" />
</StackPanel>
</StackPanel>
</Border>
C#
private Border CreateListItem(Item item)
{
// Main border
Border itemBorder = new Border();
itemBorder.BorderThickness = new Thickness(4);
itemBorder.CornerRadius = new CornerRadius(8);
itemBorder.BorderBrush = new SolidColorBrush(Colors.White);
itemBorder.Height = 70;
// Main stack panel
StackPanel mainPanel = new StackPanel();
mainPanel.Orientation = Orientation.Horizontal;
itemBorder.Child = mainPanel;
// The item's image border
Border imageBorder = new Border();
imageBorder.Margin = new Thickness(5, 0, 0, 0);
itemBorder.BorderThickness = new Thickness(2);
itemBorder.CornerRadius = new CornerRadius(2);
itemBorder.BorderBrush = new SolidColorBrush(Colors.White);
itemBorder.Background = new SolidColorBrush(Colors.White);
itemBorder.Height = 45;
itemBorder.Width = 45;
mainPanel.Children.Add(imageBorder);
// The item's image
Image image = new Image();
image.Source = new BitmapImage(new Uri("/Crystal%20Cloud;component/Resources/Images/weapons/swords/sword_0.png"));
imageBorder.Child = image;
// The stack panel for the text
StackPanel textPanel = new StackPanel();
textPanel.Margin = new Thickness(10, 0, 0, 0);
mainPanel.Children.Add(textPanel);
// The title text block
TextBlock titleText = new TextBlock();
titleText.Text = "Wooden Dagger";
titleText.FontFamily = new FontFamily("Comic Sans MS");
textPanel.Children.Add(titleText);
// The status text block
TextBlock statusText = new TextBlock();
statusText.Text = "DPS: 1";
statusText.FontFamily = new FontFamily("Comic Sans MS");
statusText.FontSize = 16;
statusText.Margin = new Thickness(15, 0, 0, 0);
textPanel.Children.Add(statusText);
return itemBorder;
}
Erg... just found the bug itemBorder should be changed to imageBorder.