I have a weird error which I can't figure out.
I am creating a Windows Phone 7 app where I create PivotItems on the fly that contains a ListBox.
Heres the code -
PivotItems = new ObservableCollection<StatusItem>();
DataTemplate itemTemplate = App.Current.Resources["PivotItemTemplate"] as DataTemplate;
ListBox itemBox = new ListBox();
itemBox.ItemsSource = PivotItems;
itemBox.ItemTemplate = itemTemplate;
CorePivotItem = new PivotItem() { Header = header, Content = itemBox };
Now when I ever I add objects to PivotItems, nothing ever shows up in the UI.
Sorry for not being clear the first time - Here is the DataTemplate binding -
<DataTemplate x:Key="PivotItemTemplate">
<StackPanel >
<Image Source="{Binding URL}" ></Image>
<TextBlock Text="{Binding Text}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/>
</StackPanel>
</DataTemplate>
I am adding the PivotItems to another OC which is binding to a Pivot control. All listings show up fine when I flick across PivotItems. Basically what I am guessing is that the OC is not triggering a refresh on the ListBox. Could I potential use BindingExpressions to force Refresh the list?
Your code doesn't show adding the newly create PivotItem to the Pivot. Is this what you're not doing.
This does of course assume that CorePivotItem is not already defined elsewhere.
Can you show your XAML and other C# code so we get the full picture.
Related
I am stuck with this annoying problem in iOS(works perfectly fine in Android) and I can't seem to find a solution at all. Could someone please help me? Thanks.
I have tabbed pages in which I have a Message Tab which consists of a collection view which shows the user messages. When the app starts I download about 5 messages and then wait for the remainingitemthresholdreached to fire so I can go ahead and fetch more data but unfortunately, it doesn't fire and I am stuck with the initial 5 messages.
XAML
<CollectionView Grid.Row="1" ItemsSource="{Binding AllMessages, Mode=TwoWay}" x:Name="myMessagesCV" SelectionMode="Single" SelectionChanged="MyMessagesCV_SelectionChanged" RemainingItemsThresholdReached="MyMessagesCV_RemainingItemsThresholdReached" RemainingItemsThreshold="5">
<CollectionView.ItemTemplate>
<DataTemplate>
// Some Code here
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
Code Behind
private void MyMessagesCV_RemainingItemsThresholdReached(object sender, EventArgs e)
{
if (IsBusy)
return;
IsBusy = true;
if (!LoadedAllMyMessages)
{
GetMyMessages();
}
if (LoadedAllMyMessages)
{
myMessagesCV.RemainingItemsThreshold = -1;
}
}
Please someone save me. Cheers guys!
The RemainingItemsThresholdReached could be triggered with enough items.
You could check it in IncrementalLoadingPage of Scrolling. Or you could use the RemainingItemsThresholdReachedCommand
Here is the example for yoru reference. https://github.com/xamarin/xamarin-forms-samples/tree/master/UserInterface/CollectionViewDemos
I've developed a Xamarin.Forms.Shell app containing 4 tabs.
I would like to add a basic audio player allowing to play music from a streaming source.
But I'm looking to the best way to manage it:
I don't want to display it in a dedicated page, as I don't get the metadata of the audio (no album photo, no title, no author, ...) and there are no "Play Next" or "Play Previous" features
I would like to display a basic view appearing at the bottom and above of the main page, containing 3 buttons (play or pause/stop/close) and the name of the radio
I would like to do something like this:
But I don't know what is the better approach to achieve this:
use a Drawer like SimpleBottomDrawer
use a Slide like SlideOverKit
use a Sheet like BottomSheet
All of these solution seem too complicated for my needs.
Is there another approach?
Here is the solution I've implemented.
By default, I display a Floating Action Button, that will show the radio player control panel.
In this panel, I have the "play"/"stop" controls, the radio title, and a "close" button to hide the panel.
The radio player control panel is hidden by default by applying a TranslationY
The XAML looks like this:
<Grid>
<!-- FloatingActionButton -->
<yummy:PancakeView x:Name="RadioFab"
CornerRadius="28"
Padding="16"
BackgroundColor="{StaticResource AccentColor}"
VerticalOptions="End"
HorizontalOptions="End"
Margin="25">
<yummy:PancakeView.Shadow>
<yummy:DropShadow Offset="1,2"
Color="{StaticResource Gray-Black}"
BlurRadius="2"
Opacity="0.2"/>
</yummy:PancakeView.Shadow>
<Image HeightRequest="24" WidthRequest="24">
<Image.Source ... />
</Image>
<yummy:PancakeView.GestureRecognizers>
<TapGestureRecognizer Tapped="RadioFab_Clicked" />
</yummy:PancakeView.GestureRecognizers>
</yummy:PancakeView>
<!-- Radio player view
<yummy:PancakeView x:Name="RadioPlayerView"
VerticalOptions="End"
HeightRequest="56"
BackgroundColor="{StaticResource Gray-400}"
Opacity="0.9"
TranslationY="56"
IsVisible="True">
<!-- content ... -->
</yummy:PancakeView>
<Grid>
When the Floating Action Button is clicked, I call the TranslateTo() method, allowing me to display the panel, and to get the expected behaviour.
The code-behind looks like this:
private void RadioFab_Clicked(object sender, EventArgs e)
{
this.RadioFab.ScaleTo(0, easing: Easing.Linear);
this.RadioPlayerView.TranslateTo(0, 0, 300);
}
void Player_CloseButton_Clicked(System.Object sender, System.EventArgs e)
{
this.RadioPlayerView.TranslateTo(0, 56, 300);
this.RadioFab.ScaleTo(1, easing: Easing.SpringOut);
}
So I implemented swipe to delete functionality for iOS and long tap to delete for Android, everything works fine except - on iOS after swiping a cell and clicking delete button I am displaying Alert to confirm if user wants to delete item# XYZ, when alerts pops up another cell gets swiped.
Any suggestions how to fix it?
XAML:
<ViewCell.ContextActions>
MenuItem CommandParameter="{Binding .}" Text="Delete" IsDestructive="True" Command="{Binding Path=BindingContext.DeleteCommand, Source={x:Reference Name=ListPage}}"
</ViewCell.ContextActions>
ViewModel (when delete command is called):
string Msg = string.Format("Delete item {0}?", selectedItem.ItemNumber);
var answer = await App.Current.MainPage.DisplayAlert(App.ResourceContainer.GetString("Confirmation_Message"),
Msg,
App.ResourceContainer.GetString("Yes"),
App.ResourceContainer.GetString("No"));
I'm having a problem with showing Dialogs from a View Model. The problem is that the "underlying content is not dimmed and disabled" as the documentation says it should be. If I click on the underlying view the button in the dialog wired to the closed command is sometimes disabled and the user is not able to click it.
I defined the DialogHost in my MainView like this (also tried it in the ShellView):
<materialDesign:DialogHost
HorizontalAlignment="Center"
VerticalAlignment="Center"
CloseOnClickAway="True" />
From my MainViewModel I show the dialog like this:
Dim errView As New ErrorView
Dim res = Await DialogHost.Show(errView)
I wired up the close command on a button in the ErrorView dialog like this:
Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}"
You problem is with the definition of DialogHost; you have it as an empty element.
The DialogHost is a ContentControl. Everything inside is what will become dimmed. So you define it at the root of your main Window/Page XAML, a bit more like:
<materialDesign:DialogHost CloseOnClickAway="True">
<StackPanel>
<TextBlock>Hello World</TextBlock>
<TextBlock>This is the main content of my application</TextBlock>
</StackPanel>
</materialDesign:DialogHost>
I have created a lookless control using silverlight 4. This control contains a textbox which the user will type data into and a button that increases the size of the textbox by increasing the MinHeight of the control by 10 each time it is pressed (I have set the textbox to stretch so it grows with the control).
This bit works fine but I now want to extend the controls functionality by adding another textbox that will display the current MinHeight of the control which I dont seem to be able to do. I have been trying
Text="{Binding RelativeSource={RelativeSource Self}, Path=MinHeight, Mode=TwoWay}">
Im not sure why but this always shows as 0
Update
In my attempts to resolve I tried chaging the name of the source textbox to PART_sourceData and just to see if the binding was correct I set the path to the text property. This appears to bring through the text of the sourcedata as I would expect
Text="{Binding Mode=TwoWay, ElementName=PART_sourceData, Path=Text}"
My next step was to change the path to Height
Text="{Binding Mode=TwoWay, ElementName=PART_sourceData, Path=Height}"
But this returns NaN. Therefore I tried MinHeight
Text="{Binding Mode=TwoWay, ElementName=PART_sourceData, Path=MinHeight}"
This always returns 0 even though the code behind has a valid number. Whats going wrong? Becuase the text comes through properly I beleive the binding to be correct but whats wrong with getting the height?
By binding to RelativeSource Self you are looking at that controls MinHeight. You will need to name your original TextBox with the x:Name attribute, then use ElementName binding.
Ok I have a solution. Not the best but it works!
I have had to create a new dependancy property
public static readonly DependencyProperty EditorHeightProperty =
DependencyProperty.Register("EditorHeight", typeof(string), typeof(EditorControl), new PropertyMetadata(default(string)));
public string EditorHeight
{
get { return (string)GetValue(EditorHeightProperty); }
set { SetValue(EditorHeightProperty, value); }
}
Then I bind the text to this property using
Text="{TemplateBinding EditorHeight}"