Evening I created a nice UI based on importing an XML file and it all works, i want to replace the button i had with a custom control (see below) i have roughed it out but i cant get the button content to bind.
Can anybody see where i screwed up?
Thanks
Madaxe
New Code
<ItemsControl ItemsSource="{Binding Software}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<CustomControls:SoftwareInstallStatus_Ctrl
ButtonContent="{Binding Name}"
ButtonWidth="100"
HorizontalAlignment="Left"
Margin="5,5,5,5"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Original Code
<!--<DataTemplate>
<Button Content="{Binding Name}"
Width="100"
HorizontalAlignment="Left"
Margin="5,5,5,5"
Tag="{Binding BindsDirectlyToSource=True}"
Command="{Binding DataContext.Btn_AddNewDataModel_Click, RelativeSource={RelativeSource AncestorType={x:Type Window}, Mode=FindAncestor}}"
CommandParameter="{Binding RelativeSource={RelativeSource Self}}"/>
</DataTemplate>-->
User Control XAML
<UserControl x:Class="Nikola_Software_Installation_App.CustomControls.SoftwareInstallStatus_Ctrl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Nikola_Software_Installation_App.CustomControls"
mc:Ignorable="d"
Name="SoftwareInstallStatusWindow"
Height="{Binding WindowHeight,ElementName=SoftwareInstallStatusWindow, FallbackValue=30}"
Width="{Binding WindowWidth,ElementName=SoftwareInstallStatusWindow, FallbackValue=220}">
<Grid>
<Button x:Name="Btn_StartDownload"
Content="{Binding ButtonContent,ElementName=SoftwareInstallStatusWindow, FallbackValue=Button}"
Width="{Binding ButtonWidth,ElementName=SoftwareInstallStatusWindow, FallbackValue=40}"
Margin="5,5,0,5"
HorizontalAlignment="Left"
Tag="{Binding ButtonTag,ElementName=SoftwareInstallStatusWindow, FallbackValue=null}"/>
<ProgressBar x:Name="Pgb_DownloadStatus"
Width="{Binding ProgressBarWidth,ElementName=SoftwareInstallStatusWindow, FallbackValue=140}"
Margin="50,5,0,5"
HorizontalAlignment="Left" />
<RadioButton x:Name="Rbn_Install"
Margin="200,8,0,8"
HorizontalAlignment="Left"/>
</Grid>
</UserControl>
User Control.CS
using Infrastructure_Project.ViewModels;
using System.Windows;
using System.Windows.Controls;
namespace Nikola_Software_Installation_App.CustomControls
{
public partial class SoftwareInstallStatus_Ctrl : UserControl
{
#region "Window"
public int WindowWidth
{
get { return (int)GetValue(WindowWidthProperty); }
set { SetValue(WindowWidthProperty, value); }
}
public static readonly DependencyProperty WindowWidthProperty =
DependencyProperty.Register("WindowWidth", typeof(int), typeof(SoftwareInstallStatus_Ctrl), new PropertyMetadata(220));
public int WindowHeight
{
get { return (int)GetValue(WindowHeightProperty); }
set { SetValue(WindowHeightProperty, value); }
}
public static readonly DependencyProperty WindowHeightProperty =
DependencyProperty.Register("WindowHeight", typeof(int), typeof(SoftwareInstallStatus_Ctrl), new PropertyMetadata(30));
#endregion
#region "Button"
public string ButtonContent
{
get { return (string)GetValue(ButtonContentProperty); }
set { SetValue(ButtonContentProperty, value); }
}
public static readonly DependencyProperty ButtonContentProperty =
DependencyProperty.Register("ButtonContent", typeof(string), typeof(SoftwareInstallStatus_Ctrl), new PropertyMetadata(string.Empty));
public int ButtonWidth
{
get { return (int)GetValue(ButtonWidthProperty); }
set { SetValue(ButtonWidthProperty, value); }
}
public static readonly DependencyProperty ButtonWidthProperty =
DependencyProperty.Register("ButtonWidth", typeof(int), typeof(SoftwareInstallStatus_Ctrl), new PropertyMetadata(100));
public object ButtonTag
{
get { return (object)GetValue(ButtonTagProperty); }
set { SetValue(ButtonTagProperty, value); }
}
public static readonly DependencyProperty ButtonTagProperty =
DependencyProperty.Register("ButtonTag", typeof(object), typeof(SoftwareInstallStatus_Ctrl), new PropertyMetadata(null));
#endregion
#region "ProgressBar"
public int ProgressBarWidth
{
get { return (int)GetValue(ProgressBarWidthProperty); }
set { SetValue(ProgressBarWidthProperty, value); }
}
public static readonly DependencyProperty ProgressBarWidthProperty =
DependencyProperty.Register("ProgressBarWidth", typeof(int), typeof(SoftwareInstallStatus_Ctrl), new PropertyMetadata(140));
#endregion
public SoftwareInstallStatus_Ctrl()
{
InitializeComponent();
DataContext = new SoftwareInstallStatus_ViewModel();
}
}
}
