如何從密封部分類中的函數返回值?返回類別
我使用像這樣的usercontrols。我有一個用戶控件,調用另一個是列表。當我從這個列表中選擇一行時,我調用SelectionChanged =「RadGrid1_SelectedIndexChanged」,它保存在我想要保存的行的模板類型的變量上。 (直到這裏沒有問題)
當在主頁我試圖訪問該變量,它總是返回我空。 (這裏的問題)
用戶控件:
<UserControl
x:Class="Stuff.Grouping.TableControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Stuff.Grouping"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">
<Grid>
<SemanticZoom ScrollViewer.HorizontalScrollMode="Disabled" ScrollViewer.VerticalScrollMode="Disabled">
<SemanticZoom.ZoomedInView>
<local:GroupingZoomedInView Margin="0 0 30 50"/>
</SemanticZoom.ZoomedInView>
<SemanticZoom.ZoomedOutView>
<GridView Margin="30 30 30 50">
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<WrapGrid Orientation="Horizontal" MaximumRowsOrColumns="7"/>
</ItemsPanelTemplate>
</GridView.ItemsPanel>
<GridView.ItemTemplate>
<DataTemplate>
<Border Background="#FF3399FF" MinWidth="100" MinHeight="100">
<TextBlock Text="{Binding}" FontSize="60" Margin="10"/>
</Border>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
</SemanticZoom.ZoomedOutView>
</SemanticZoom>
</Grid>
</UserControl>
GroupingZoomedInView.xaml
<UserControl
x:Class="Stuff.Grouping.GroupingZoomedInView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Stuff.Grouping.Data"
xmlns:telerikGrid="using:Telerik.UI.Xaml.Controls.Grid"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">
<Grid>
<Grid.Resources>
<local:PeopleViewModel x:Key="Model"/>
</Grid.Resources>
<telerikGrid:RadDataGrid x:Name="dataGrid" ItemsSource="{Binding Data,Source={StaticResource Model}}" AutoGenerateColumns="False" FontSize="{StaticResource ControlContentThemeFontSize}" SelectionChanged="RadGrid1_SelectedIndexChanged">
<telerikGrid:RadDataGrid.GroupDescriptors>
<telerikGrid:DelegateGroupDescriptor>
<telerikGrid:DelegateGroupDescriptor.KeyLookup>
<local:AlpabeticGroupKeyLookup/>
</telerikGrid:DelegateGroupDescriptor.KeyLookup>
</telerikGrid:DelegateGroupDescriptor>
</telerikGrid:RadDataGrid.GroupDescriptors>
<telerikGrid:RadDataGrid.Columns>
<telerikGrid:DataGridTextColumn PropertyName="Template"/>
<telerikGrid:DataGridTextColumn PropertyName="data"/>
<telerikGrid:DataGridTextColumn PropertyName="info"/>
<telerikGrid:DataGridTextColumn PropertyName="score"/>
<telerikGrid:DataGridTextColumn PropertyName="result"/>
<telerikGrid:DataGridTextColumn PropertyName="repeats"/>
</telerikGrid:RadDataGrid.Columns>
</telerikGrid:RadDataGrid>
</Grid>
</UserControl>
GroupingZoomedInView.xaml.cs
public sealed partial class GroupingZoomedInView : UserControl, ISemanticZoomInformation
{
public void RadGrid1_SelectedIndexChanged(object sender, DataGridSelectionChangedEventArgs e)
{
template = (Templates)dataGrid.SelectedItem;
}
public void StartViewChangeFrom(SemanticZoomLocation source, SemanticZoomLocation destination)
{
source.Item = this.dataGrid.GetDataView().Items.OfType<IDataGroup>().Select(c => c.Key);
}
public void StartViewChangeTo(SemanticZoomLocation source, SemanticZoomLocation destination)
{
var dataview = this.dataGrid.GetDataView();
var group = dataview.Items.OfType<IDataGroup>().Where(c => c.Key.Equals(source.Item)).FirstOrDefault();
var lastGroup = dataview.Items.Last() as IDataGroup;
if (group != null && lastGroup != null)
{
this.dataGrid.ScrollItemIntoView(lastGroup.ChildItems[lastGroup.ChildItems.Count - 1],() =>
{
this.dataGrid.ScrollItemIntoView(group.ChildItems[0]);
});
}
}
public Func<Templates> GetTemplateMethod()
{
return() => this.template;
}
}
在這裏,我需要的模板值返回炫魅廣東。我怎樣才能做到這一點?
public MainPage()
{
GroupingZoomedInView gView = new GroupingZoomedInView();
Func<Templates> method = gView.GetTemplateMethod();
Templates temp = method();
}
public class Templates(){
public String filename { get; set; }
public String data { get; set; }
}
如果你不*使用密封的部分類,你會怎麼做? (這些都不影響這個......) – 2013-03-08 04:15:16
我想知道如何從類中返回值。 – 2013-03-08 04:18:27
所以'GroupingZoomedInView'是一個控件,它允許一個控件允許用戶從數據綁定列表中選擇一個模板。在你的MainPage方法中,你實例化一個新的實例並立即嘗試獲取選定的模板。您從未將'gView'放置在任何位置的屏幕上,或允許用戶在嘗試從'gView'中獲取它之前選擇模板。您可能需要引用現有的「gView」,而不是創建新的「gView」。 – 2013-03-09 00:16:49