自學程序員,會喜歡任何有關我的代碼的建設性批評。UWP從DataTemplate對象調用方法
我有一個ListView,將ListViewItems,我想要自定義。
我所做的ListViewItem有兩個TextBlocks和一個ToggleSwitch。當ToggleSwitch打開/關閉時,我希望它從一個實例化對象中調用一個方法,或者調用一個來自同一個表單的方法,但以某種方式檢索最初加載到DataTemplate中的對象。
這裏是XAML至今:
<ListView x:Name="listViewAddedVideoFolders" Grid.Row="1" DoubleTapped="listViewAddedVideoFolders_DoubleTapped" SelectionChanged="listViewAddedVideoFolders_SelectionChanged" HorizontalContentAlignment="Stretch">
<ListView.ItemTemplate>
<DataTemplate>
<Grid HorizontalAlignment="Stretch">
<TextBlock HorizontalAlignment="Stretch" VerticalAlignment="Center" Text="{Binding Directory}"/>
<Grid HorizontalAlignment="Right">
<StackPanel>
<TextBlock Text="Find Videos: "></TextBlock>
<ToggleSwitch Toggled="listViewVideoFolder_toggled" />
</StackPanel>
</Grid>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListView.ItemContainerStyle>
現在它被調用listViewVideoFolder_toggled
之前,我試圖用切換= 「{結合StartCrawling()}」
這裏AddVideoFolderModel對象,我綁定listviewitems到
namespace Movie_Management_Windows_10.Models
{
public class AddVideoFolderModel
{
public static ObservableCollection<AddVideoFolderModel> MyVideoFolderModels = new ObservableCollection<AddVideoFolderModel>();
public int VideosFound { get; set; }
public string Directory { get; set; }
public string DirectoryName { get; set; }
private bool isCrawling = false;
public bool HasBeenCrawled = false;
private void startCrawling()
{
AppShell.Current.NotifyUser("Crawling began", AppShell.NotifyType.StatusMessage);
}
//public override string ToString()
//{
// return Directory + " (" + VideosFound.ToString() + ")";
//}
}
}
我必須執行哪些操作才能完成此操作?
我也嘗試INotifyPropertyChanged的,我會再追求這一點。謝謝! – Illuminati
名稱空間不存在與那些對象 – Illuminati
哪一個?第一種情況或第二種? –