Sunday, June 29, 2014

Provide access to Custom Control Method


Hi Talha,


I don't get what you want to do. It would be helpful to have some code that shows what you're doing and where the problem is. :)




Thomas Claudius Huber



"If you can't make your app run faster, make it at least look & feel extremly fast"



My latest app: The "Womanizer" :-)

twitter: @thomasclaudiush

homepage: http://ift.tt/1fArvuE

author of: ultimate Windows Store Apps handbook | ultimate WPF handbook | ultimate Silverlight handbook




<UserControl
x:Class="CustomControls.CustomListView"
xmlns="http://ift.tt/w9rHWX;
xmlns:x="http://ift.tt/zZkFEV;
xmlns:local="using:CustomControls"
xmlns:d="http://ift.tt/PuXO1J;
xmlns:mc="http://ift.tt/R4RR6u;
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">



<ListView x:Name="RootListView"
SelectionMode="Extended"
CanDragItems="True"
SelectionChanged="SelectionChanged"
AllowDrop="True"
DragItemsStarting="RootListView_DragItemsStarting"
Drop="DragDropped"
Header="{Binding Header}"
HeaderTemplate="{Binding HeaderTemplate}"
ItemsPanel="{Binding ItemsPanel}"
Background="{Binding ActualBackground}"
ItemsSource="{Binding ItemsSource}"
Foreground="{Binding ActualForeground}"
BorderThickness="{Binding ActualBorderThickness}"
BorderBrush="{Binding ActualBorderBrush}"
ItemTemplate="{Binding ItemTemplate}"
ContainerContentChanging="ItemsChanged"
>
</ListView>
</UserControl>

I have a control like this. To expose the properties of inner control, I used binding. So, the user of CustomListView can change properties of inner ListView by changing CustomListView properties. Now, I have written a EventHandler for "Checkbox.Checked" and "Checkbox.Unchecked" in code behind of CustomListView.(Say EventHandler is named CheckChangedHandler)


CustomListView can be used like this:



<Page xmlns="http://ift.tt/w9rHWX;
xmlns:x="http://ift.tt/zZkFEV;
xmlns:local="using:TimeTable_c_sharp"
xmlns:Controls="using:CustomControls"
xmlns:d="http://ift.tt/PuXO1J;
xmlns:mc="http://ift.tt/R4RR6u;
xmlns:ProjectClasses="using:ProjectClasses"
xmlns:UI="using:Microsoft.Advertising.WinRT.UI"
x:Class="TimeTable_c_sharp.MainPage"
mc:Ignorable="d">

<Page.Resources>
<Style TargetType="Controls:CustomListView" x:Key="CListViewStyle1">
<Setter Property="Height" Value="346" />
<Setter Property="Width" Value="425" />
<Setter Property="VerticalAlignment" Value="Top" />
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="AllowDrop" Value="True" />
<Setter Property="ActualBackground" Value="#FF1D2E42" />
<Setter Property="ActualBorderBrush" Value="#FF575757" />
<Setter Property="ActualBorderThickness" Value="1" />
</Style>

<DataTemplate x:Key="AllSubjectsHeaderTemplate">
<Border BorderBrush="#FF677E7B"
BorderThickness="0,0,0,1"
Background="#FF534C4C">
<StackPanel Orientation="Horizontal">
<CheckBox x:Name="checkBox"
HorizontalAlignment="Left"
Margin="10"
VerticalAlignment="Top"
IsChecked="{Binding IsChecked, Mode=TwoWay}"
Width="27" />

<TextBlock Grid.Column="1"
TextAlignment="Center"
Text="{Binding Content.Column1, RelativeSource={RelativeSource Mode=TemplatedParent}}"
Margin="22,10,0,0"
TextWrapping="Wrap"
FontStyle="Normal"
FontWeight="Bold"
FontSize="18"
VerticalAlignment="Top"
Width="298"
Height="24"
x:Name="Header1"
Foreground="#FFB2BF8F" />
</StackPanel>
</Border>
</DataTemplate>
</Page.Resources>

<Controls:CustomListView x:Name="allSubjectsList"
Margin="266,141,0,0"
Header="{Binding AllSubjectsHeader}"
ItemsSource="{Binding AvailibleSubjects}"
Style="{StaticResource CListViewStyle1}"
HeaderTemplate="{StaticResource AllSubjectsHeaderTemplate}"
/>
</Page>



As you can see, user can change templates of CustomListView->RootListView. Now, there is a checkbox in Datatemplate user applied as HeaderTemplate. I want to give user ability to add following line in that checkbox.



<CheckBox Checked=<!-- Event Handler for check changed defined in CustomListView code behind -->
/>

Hope, you understands this.


No comments:

Post a Comment