Is there a way to make automatic these changes of image on a carouselView in xamarin 4.2? I named the xamarin forms version because in this version there is a CarouselView, so I am not able to use the old nuget.org/packages/Xamarin.Forms.CarouselView/2.3.0-pre1
In that old version there was a Position property which cold be set to any item in this new version included on xamarinForms 4.2, that property is missing
What I want to create is something to show a different image every 4 seconds, do you have any suggestion?
i have create automatic slider using the following code in constructor.
Device.StartTimer(TimeSpan.FromSeconds(5), () =>
{
if (listOfSpotlight.Count == 0 || listOfSpotlight == null)
{
return true;
}
slidePosition++;
if (slidePosition == listOfSpotlight.Count) slidePosition = 0;
caroselView.Position = slidePosition;
return true;
});
The Xamarin.Forms.CarouselView has been having a bunch of issues lately and I am not sure how exactly all of a sudden Xamarin decided to add it to the 4.2 release. Also it seems as if there are no properties in it which is weird. Anyway, I was facing weird issues with Xamarin's Carousel so I started using the CarouselView.FormsPlugin and it works amazingly in all situations.
Nuget: https://www.nuget.org/packages/CarouselView.FormsPlugin/
Github: https://github.com/alexrainman/CarouselView
FYI it has all the properties that XF carousel does and more:
Add the following namespace:
xmlns:controls="clr-namespace:CarouselView.FormsPlugin.Abstractions;assembly=CarouselView.FormsPlugin.Abstractions"
And then use it something like this:
<controls:CarouselViewControl Orientation="Horizontal" InterPageSpacing="10" Position="{Binding myPosition}" ItemsSource="{Binding myItemsSource}" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
<controls:CarouselViewControl.ItemTemplate>
<DataTemplate>
<local:MyView /> <!-- where MyView is a ContentView -->
</DataTemplate>
</controls:CarouselViewControl.ItemTemplate>
</controls:CarouselViewControl>
For finding additional properties look for Bindable Properties section of the homepage at Git.
You can try Chetan Rawat's answer or
Device.StartTimer(TimeSpan.FromSeconds(4), (Func<bool>)(() =>
{
cView.Position = (cView.Position + 1) % imagesList.Count;
return true;
}));
*here cView is my carousel view and imageList is my list that contains the images that have to be slided in carousel view .
Happy Coding :)
I've been developing a UWP project in my spare time to get a hang of UWP, MVVM and Prism. The project was originally really classic, with no use of MVVM and Prism, and I've been working to get those 2 into the project. I've been relying on https://msdn.microsoft.com/en-us/library/gg405484(v=pandp.40).aspx, https://msdn.microsoft.com/en-us/library/gg405494(v=pandp.40).aspx and https://msdn.microsoft.com/en-us/library/ff921098(v=pandp.40).aspx to work my way through it.
Some background: I originally had a direct function call from my Mainpage.xaml to the MainPage.xaml.cs codebehind, but during the conversion to MVVM and a separate usercontrol, I removed that function call so I could later using Command Binding. After I removed that, I got an error that was somewhere in GameRouletteView.g.i.cs that was a remnant of this removed function call, where the g.i.cs file assumed it was still bound. I rebuilt my project and those g.i.cs files apparently got removed.
I added the following lines to my Usercontrol View so my ViewModel gets added:
xmlns:gameRoulette="using:GameRoulette.DesignViewModels"
xmlns:prism="using:Prism.Windows.Mvvm"
d:DataContext="{d:DesignInstance gameRoulette:GameRouletteDesignViewModel, IsDesignTimeCreatable=True}"
prism:ViewModelLocator.AutoWireViewModel="True"
Full Code:
<UserControl
x:Class="GameRoulette.Views.GameRouletteView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:GameRoulette.Views"
xmlns:gameRoulette="using:GameRoulette.DesignViewModels"
xmlns:prism="using:Prism.Windows.Mvvm"
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"
d:DataContext="{d:DesignInstance gameRoulette:GameRouletteDesignViewModel, IsDesignTimeCreatable=True}"
prism:ViewModelLocator.AutoWireViewModel="True">
<Grid Background="White">
<Button x:Name="btnSelectGames" Content="Click here to select your games"
HorizontalAlignment="Left" Margin="110,50,0,0"
VerticalAlignment="Top" Height="40" Width="240"
Click="{Binding SelectCommand}"/>
<Button x:Name="btnChooseGame" Content=""
HorizontalAlignment="Left" Margin="110,150,0,0"
VerticalAlignment="Top" Width="240" Height="40"
Click="{Binding ChooseCommand}" IsEnabled="True"/>
<ProgressRing HorizontalAlignment="Left" Margin="200,100,0,0"
VerticalAlignment="Top" RenderTransformOrigin="1.05,1.983"
Height="45" Width="45" IsActive="True" Visibility="{Binding }"/>
<Image x:Name="imgFileIcon" HorizontalAlignment="Left"
Height="64" Margin="110,224,0,0"
VerticalAlignment="Top" Width="64" />
<TextBlock x:Name="lblFileName" HorizontalAlignment="Left"
Margin="179,224,0,0" TextWrapping="Wrap"
Text="" VerticalAlignment="Top" Width="171" Height="64"/>
</Grid>
</UserControl>
It gave the following error:
The name "GameRouletteDesignViewModel" does not exist in the namespace "using:GameRoulette.DesignViewModels".
I rebuilt the project, and then it gave the following error for each of my 3 .xaml files: GameRouletteView, App.xaml andMainPage.xaml:
'GameRouletteView' does not contain a definition for 'InitializeComponent' and no extension method 'InitializeComponent' accepting a first argument of type 'GameRouletteView' could be found (are you missing a using directive or an assembly reference?)
Also, when first opening the project, I get the Intellisense errors:
[Failure] Could not find file 'C:\Users\username\Source\Repos\GameRoulette\GameRoulette\GameRoulette\obj\ARM\Debug\MainPage.g.i.cs'.
[Failure] Could not find file 'C:\Users\username\Source\Repos\GameRoulette\GameRoulette\GameRoulette\obj\ARM\Debug\Views\GameRouletteView.g.i.cs'.
[Failure] Could not find file 'C:\Users\username\Source\Repos\GameRoulette\GameRoulette\GameRoulette\obj\ARM\Debug\App.g.i.cs'.
Things I've ruled out:
My namespaces are correct;
I've tried https://stackoverflow.com/a/27260580/1770430, didn't work;
i've deleted the bin, obj folders and the .suo file, didn't fix it;
I've closed and reopened the solution, did not fix it.
Repair Visual Studio through the add/repair/remove programs window, no result.
I've googled this error, but I can't really find anything that I haven't tried yet.
I've also noticed that my NuGet Packages have gone missing and that my Package Manager Console does not recognize NuGet anymore. I also get this error:
Microsoft.NETCore.Portable.Compatibility 1.0.0 provides a compile-time reference assembly for mscorlib on UAP,Version=v10.0, but there is no run-time assembly compatible with win10.
I got a feeling that all these issues are related, but I can't figure out what's wrong with it. As mentioned above, Google doesn't really provide much assistance, and what it does provide doesn't work.
I'm using Visual Studio 2015 Community Edition with Update 1. The project can be found at https://github.com/nzall/GameRoulette.
I've struggled with this issue for a couple of days, and, at least in my case, I'm pretty sure that it depended on some subtle bug that I introduced inadvertently in my xaml code. Or, better, not exactly a bug, but something that's not supported by the version of xaml for the platform we are targeting. In that case the xaml parser fails, and the g.i.cs files (which contain the part of the pages and app classes generated by the parser, including the InitializeComponent method) are not generated as expected.
Why do I believe that?
At first, I thought it was a problem with Visual Studio, so I cleared component cache, then deleted completely the folder C:\Users{myname}\AppData\Local\Microsoft\VisualStudio\14.0, then I disinstalled and then reinstalled VS from scratch. I still had the error.
When I tried to build the solution, in the error windows I Only saw a generic 'Object reference not set to an instance of an object', but if I examined build output window, I could see that the problem was in effect related to the xaml parser (precisely: Xaml Internal Error WMC9999).
There's not so much on the internet about this issue, a part for a few help request by people facing the same situation, but the only two pages I managed to found that do offer a solution both linked this problem to the use of (different) unsupported functionality in xaml (code that is syntactically correct but unsupported by the target platform): see here and here.
I finally managed to get rid of the errors simply by undoing the last changes with my source control repository. Unfortunately, I had made a lot of change in code, so I can't say which was the exact line of code that caused the problem in my case. But the takeaway of this story is that every evidence points to the fact that it was something related to my xaml code. So, even if, of course, one can't exclude that sometimes there could be a major, system-wide issue with the xaml parser, I would advise other people facing this problem first to quickly undo the last changes and see if the problem disappears.
I have ShellView which is conductor. It contains StartView, where I create Appbar. But there is a lot of another views in my application and appbar looks similar on all screens so I have made AppBarView and AppBarViewModel.
My AppBar defined like this:
***StartView***
<Page.BottomAppBar>
<AppBar x:Name="BottomAppBar">
<Grid HorizontalAlignment="Right" >
<local:AppBarView Caliburn:Bind.Model="{Binding AppBarViewModel}" />
</Grid>
</AppBar>
</Page.BottomAppBar>
***AppBarView***
<StackPanel Orientation="Horizontal">
<Button Name="Play" Style="{StaticResource PlayAppBarButtonStyle}" />
</StackPanel>
I also create AppBarViewModel with method Play (It's by CM conventions).
When i run application and open AppBar first time my button not works. But if I hide and open again AppBar - all works great.
Any ideas why it not works at first time?
Thank you!
UPD:
There is error in output window in debug:
Error: BindingExpression path error: 'AppBarViewModel' property not found on 'MusicMaker.ViewModels.AppBarViewModel, MusicMaker, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. BindingExpression: Path='AppBarViewModel' DataItem='MusicMaker.ViewModels.AppBarViewModel, MusicMaker, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'; target element is 'MusicMaker.Views.AppBarView' (Name='null'); target property is 'Model' (type 'Object')
I have two suggestions for you Alexei but they may not work but at least you can try:
Replace Caliburn:Bind.Model="{Binding AppBarViewModel}" with Caliburn:View.Model="{Binding AppBarViewModel}".
If the first option doesn't work then check out this Screens, Conductors and Composition article to see how the author did View-First, pay attention that he used a string instead of a binding markup inside Caliburn:Bind.Model="{Binding AppBarViewModel}".
That is all i can say. Hope it helps.
The exception in the title is thrown when I open a window in WPF, the strange thing is that this does not happen on my Windows 7 development machine nor does it happen when it is deployed on Windows 7.
I only get this error on Windows XP, and only the second time that I open the window.
Here is the code to open the window:
ReportParametersWindow win = null;
bool canOverWrite = _shownReports.Contains(rpt.FriendlyName);
if (!(canOverWrite))
win = new ReportParametersWindow(rpt.FriendlyName, rpt.ReportParameters, canOverWrite);
else
win = new ReportParametersWindow(rpt.FriendlyName, (container.ParametersWindow as ReportParametersWindow).Controls, canOverWrite);
win.ShowDialog();
And the XAML for the window:
<Window xmlns:my="clr-namespace:MHA.Modules.Core.Controls;assembly=MHA.Modules.Core"
x:Class="MHA.Modules.Reports.Views.ReportParametersWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Parameters" Height="500" Width="600" MinWidth="500" MaxHeight="500"
Icon="/MHA.Modules.Reports;component/Images/Parameters.ico" SizeToContent="WidthAndHeight"
WindowStartupLocation="CenterScreen"
xmlns:odc="clr-namespace:Odyssey.Controls;assembly=Odyssey" Closed="Window_Closed">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="40"/>
</Grid.RowDefinitions>
<ScrollViewer Grid.Row="0" Name="ScrollViewer1" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" CanContentScroll="True">
<StackPanel Name="ParameterStack">
<my:LocationCtl Text="Parameters for report - " Name="loc"/>
</StackPanel>
</ScrollViewer>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<CheckBox ToolTip="This will replace the first report of the same type that was shown." Name="chkOverwrite" Content="Overwrite old" VerticalAlignment="Center" Margin="5,0"></CheckBox>
<Button Grid.Column="2" HorizontalAlignment="Right" Margin="5,0" Height="30" Style="{StaticResource DionysusButton}" Width="100" IsDefault="True" Click="Button_Click">
<StackPanel Orientation="Horizontal">
<Image Source="/MHA.Modules.Reports;component/Images/Success.png"></Image>
<TextBlock Margin="5,0" Text="Accept" VerticalAlignment="Center"></TextBlock>
</StackPanel>
</Button>
</Grid>
</Grid>
Does anyone have suggestions?
The solution is quite a weird one but I have it figured out.
I realized that the error was occurring on the InitializeComponent() of the window, I then added a try catch to the constructor and showed the InnerException of the Exception.
The error that I received is "Image format not recognized".
I have no idea why this happens only on XP and the second time that the window is shown but by replacing my .ico with a .png the problem was resolved.
Hope this helps someone.
I just ran into this issue as well... I know this is old, but what I had to end up doing was set the images to Resource, and Copy Always... only by browsing my /bin/Debug folder did I realize that the images were not at a valid path location
This problem can also occur if the required image is not available at the specified location. So Check the inner exception and add any image that might have been missed or misspelled.
I got this error because my Command Binding of a Button was wrong:
<Button Command="MyCommand" />
instead of
<Button Command="{Binding MyCommand}" />
You Should first Import Image to your project
Solution Explorer - Show All
then Right Click on the image and select Include
Now Use
end
In my case the root cause was wrong BuildAction property on all images. I fixed it by changing BuildAction from Content to Resource.
I got this exception after moving my Resource Dictionary from root of my application to a subdirectory. In my case the problem were Image paths inside my Style setters inside the dictionary. After I preceded them with a forward slash '/', the application started to work again. If you're having a similar problem, open the resource dictionary, and the error will be highlighted with the blue 'squiggly' line.
In my case, I have added 'WpfToolkit' refrence to my module, and there is no need.
After deleting this reference, everything was ok. Strange!
Just go to Project>[Your Project Name] Settings and set your .ico file as icon now your .ico file is mentioned in your manifest file and you can simply include your .ico file in your XAML file using
Icon="[icon file name].ico"
<Window x:Class="[Your project's name].MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="" Height="500" Width="720"
Icon="[your icon's name].ico">
In my case, I found the mew added icon(image) file is not added into my project. It is resolved after I added these new image files into my project, not just file copy.
In my case the files existed on disk but were not referenced in the project. I added them to the project but the error persisted despite reloading the solution and restarting Visual Studio.
I changed the references to an existing file that was already in the project and it ran fine (albeit with the wrong graphic). I then changed it back to the original reference and it ran fine again but with the correct image. Presumably the error was getting cached somehow until it was flushed out of the system...
Remove the "WPFToolkit" reference from your cs.proj file.
<Reference Include="WPFToolkit, Version=3.5.40128.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
It should do the trick.
copy and paste the file name is changed. that's why I get this error.
well, in my case I added the new photos to the image Folder in FileExplore while image folder was added to the project while ago. and there wasn't any problem with the image path in the project. but when I build the project I face to the same error.
then I add those new photos to project by right click on the image folder and add the existing item and selected new photos. then I cleaned the solution and build it again.
There are many ways to cause this issue. Since the exception isn't specific. Here is a list of solutions to try from this thread.
Firstly, you can try/catch the InitializeComponent() call which is throwing the exception to get more details about what happened.
If the image is an icon (.ico) file use an image (.png) or equivalent instead
In some cases .ico files are problematic - I was using .NETCore
Make sure your image file has a build action of Resource or Embedded Resource
The resource files described in this section are different than the
resource files described in XAML Resources and different than the embedded
or linked resources described in Manage Application Resources (.NET). - MSDN
Ensure your reference to the file is spelled and pathed correctly
Example: "/Resources/logo.png" if you have a folder at the project level
Notice the prefix /.
Colors codes in the xaml file missing the hashtag prefix "#000FE0"
In my case, another program was using the image and somehow was blocking the access.
I mad a copy and this worked.
<Window
.....
Height="450" Width="400"
Icon="../Resources/SettingsCopy.png" >
To improve upon user2125523:
If you've added the image to the project and checked and double checked that the file spelling is correct, try renaming the image to mirror a different existing image. Build/run, then put your image file name back and build/run again.
For example:
My original code kept throwing the OP error on LargeImage="/img/32/delete.order.png" even though this file exists.
<telerik:RadRibbonButton Text="Object Properties" Size="Large"
Name="PropertiesButton" IsTabStop="True"
telerik:ScreenTip.Description="Get object properties"
Click="PropertiesButton_Click"
LargeImage="/img/32/properties.png"
SmallImage="/img/16/properties.png" />
<telerik:RadRibbonButton Text="Reset Tab Order" Size="Large"
Name="ClearTabOrderButton" IsTabStop="True"
telerik:ScreenTip.Description="Reset tab order of all fields"
Click="ClearTabOrder_Click"
LargeImage="/img/32/delete.order.png"
SmallImage="/img/16/delete.order.png" />
So, I changed LargeImage="/img/32/delete.order.png" to LargeImage="/img/32/properties.png", ran the program, and changed it back to "/img/32/delete.order.png". Finally the error was gone.
FYI VS2012.3 Win8.1Preview
I had the same issue and to add an image to you solution you have to do it through the wizzard. In the solution explorer -> right click on the appropriate folder-> add existing Item -> and then browse to your image. That worked for me. Hope this helps.
Thanks for you answers.
Try to set Build Action of Property of Image file as Resource.
Exception used to occur within constructor. Button's command binding was incorrect.
Eg: <Button Command="MyCommand" />--> Wrong
<Button Command="{Binding MyCommand}" />--> Right
In my case, I got this error when I had
<Border Background="eeeeee">
instead of
<Border Background="#eeeeee">
(notice the missign #)
I found "UpdateSourceTrigger=Pr" somewhere in my XAML.
Must have happened during editing.
Compiling went OK, no error then whatsoever.
Setting a BreakPoint in Application_DispatcherUnhandledException in app.xaml.cs revealed the error.
Corrected to "UpdateSourceTrigger=PropertyChanged" and the world was at it should have been.
I work on Win 10 Pro, VS2017
I encountered this error and figured out that the Image Source path format has a mistake. a forward slash / was added as follows:
Source="/TestProject;component/Images//hat_and_book.png
I removed that extra slash and the error had gone.
I got the same error message, then I find this solution :
Image not displaying at runtime C# WPF
Find your folder:Go to properties of the added image, set Build Action =>as Resource and Copy To Output Directory =>as Copy if newer.
In My case I have wrote a border tag with height property then i had to remove the value leaving the property like this
<Border Background="{StaticResource MainBackgroundBrush}" BorderThickness="1" Height="">
</Border>
The Compiler gave me the same error but the IDE have no problem so after some hard search i have found it. so make sure every property is properly set. I hope this would be useful for anyone.
it is caused by Non-standard tag option in xaml to find it set
InitializeComponent();
Function in - try mode - like this
try {
InitializeComponent();
}
catch (Exception ex) {
MessageBox.Show(ex.Message.ToString());
}
now MessageBox(( show line number with incorrect setting in control .axml file.(it just show first incorrect line tag error after Corrected it then run app again and see next one)
So I was have a combobox like below, coded like this;
AllowsTransparency="True" Background="Transparent">
<Border CornerRadius="10" Background="Beige" BorderBrush="Aqua" BorderThickness="2">
<Grid>
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
<Label Name="lblText"></Label>
<ComboBox Name="cbxNumbers"></ComboBox>
<TextBox Name="txtNumbers" Visibility="Collapsed"></TextBox>
<Button HorizontalAlignment="Center" Name="btnDone"
Click="btnDone_Click">That's Right!</Button>
</StackPanel>
<Button VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="1"
FontSize="8" Name="btnChangeInput" Click="btnChangeInput_Click">Let me chose the number
</Button>
</Grid>
</Border>
And then populated in code like this;
lblText.Content = Text;
cbxNumbers.Items.Add(5);
cbxNumbers.Items.Add(10);
cbxNumbers.Items.Add(50);
cbxNumbers.Items.Add(100);
cbxNumbers.Items.Add(1000);
cbxNumbers.Items.Add(10000);
cbxNumbers.Items.Add(100000);
cbxNumbers.Items.Add(1000000);
cbxNumbers.SelectedIndex = 0;
My question is obviously, why is my Dropdown showing beneath my window?
UPDATE
Quote Microsoft
Thank you for reporting this issue. Though this issue is under
investigation, we will likely not have a fix available in .NET 4.0. We
will update this bug again when we are able to fix the issue in a
future release. Thanks!
Great... any ideas for a work around?
This is a well documented bug with AllowTransparency=TRUE. It only happens on some computers running Win XP.
http://connect.microsoft.com/VisualStudio/feedback/details/465964/wpf-combobox-dropdown-list-appears-behind-the-form-when-allowstransparency-true
A workaround is found here:
As noted before, this is an issue with layered windows on XP. There is
not much that can be done at the WPF level to solve this, and given
that XP is no longer being serviced this isn't very likely to be
fixed. There are potentially workarounds you can employ, though.
The source of the problem is that WPF uses something called "Layered
Windows" when WindowStyle=None and AllowsTransparency=True. Often the
reason for doing this is to implement custom window chrome. Recently
the WPF team published a library that allows you to get custom chrome
without resorting to layered windows. The library is available at
http://code.msdn.microsoft.com/WPFShell
This doesn't support per-pixel opacity, but it does allow for
completely custom rendering of the window, including areas normally
managed by the system. It lets you set the radii of the windows
corners, but not have a completely arbitrary shape. If you can use
this library instead of AllowsTransparency=True then it should solve
this issue.
Microsoft has issued a hotfix, but it seems to not have fixed all problems related to the issue.